Stream custom live channels using your own media
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

38 lines
1.1 KiB

using ErsatzTV.Core;
namespace ErsatzTV;
using System.Diagnostics;
public class SlowApiHandler(ILogger<SlowApiHandler> logger) : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request,
CancellationToken cancellationToken)
{
if (SystemEnvironment.SlowApiMs > 0)
{
var stopwatch = Stopwatch.StartNew();
var response = await base.SendAsync(request, cancellationToken);
stopwatch.Stop();
if (stopwatch.ElapsedMilliseconds > SystemEnvironment.SlowApiMs.Value)
{
string uri = request.RequestUri?.ToString() ?? "Unknown URI";
string method = request.Method.Method;
logger.LogDebug(
"[SLOW API] {Method} {Uri} took {Milliseconds}ms",
method,
uri,
stopwatch.ElapsedMilliseconds);
}
return response;
}
return await base.SendAsync(request, cancellationToken);
}
}