Radarr/src/Radarr.Http/Middleware/CacheHeaderMiddleware.cs
ta264 aca669defe Fixed: UI not updating on upgrade
(cherry picked from commit d566c1efd42f9a94c524db311e8fa99bc6e0323f)
(cherry picked from commit 4b0586bd3d1cca4682dee53cc5af5ef1fa66978e)
(cherry picked from commit 5b2affcabbc38d7122b39d3290e2021fdb8afbcc)
2021-10-25 13:45:44 -04:00

35 lines
1,004 B
C#

using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Radarr.Http.Extensions;
namespace Radarr.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);
}
}
}