mirror of
https://github.com/Radarr/Radarr
synced 2025-12-31 20:55:25 +01:00
(cherry picked from commit d566c1efd42f9a94c524db311e8fa99bc6e0323f) (cherry picked from commit 4b0586bd3d1cca4682dee53cc5af5ef1fa66978e) (cherry picked from commit 5b2affcabbc38d7122b39d3290e2021fdb8afbcc)
35 lines
1,004 B
C#
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);
|
|
}
|
|
}
|
|
}
|