mirror of
https://github.com/Readarr/Readarr.git
synced 2026-01-31 17:21:28 -05:00
36 lines
1006 B
C#
36 lines
1006 B
C#
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Readarr.Http.Extensions;
|
|
|
|
namespace Readarr.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);
|
|
}
|
|
}
|
|
}
|