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.
Lidarr/src/Lidarr.Http/Middleware/CacheHeaderMiddleware.cs

36 lines
1004 B

using System.Threading.Tasks;
using Lidarr.Http.Extensions;
using Microsoft.AspNetCore.Http;
namespace Lidarr.Http.Middleware
{
public class CacheHeaderMiddleware
{
private readonly RequestDelegate _next;
private readonly ICacheableSpecification _cacheableSpecification;
public CacheHeaderMiddleware(RequestDelegate next, ICacheableSpecification cacheableSpecification)
{
_next = next;
_cacheableSpecification = cacheableSpecification;
}
public async Task InvokeAsync(HttpContext context)
{
if (context.Request.Method != "OPTIONS")
{
if (_cacheableSpecification.IsCacheable(context.Request))
{
context.Response.Headers.EnableCache();
}
else
{
context.Response.Headers.DisableCache();
}
}
await _next(context);
}
}
}