mirror of
https://github.com/fergalmoran/Readarr.git
synced 2026-03-09 06:55:44 +00:00
42 lines
1.0 KiB
C#
42 lines
1.0 KiB
C#
using System;
|
|
using Nancy;
|
|
using Nancy.Bootstrapper;
|
|
using Readarr.Http.Frontend;
|
|
|
|
namespace Readarr.Http.Extensions.Pipelines
|
|
{
|
|
public class CacheHeaderPipeline : IRegisterNancyPipeline
|
|
{
|
|
private readonly ICacheableSpecification _cacheableSpecification;
|
|
|
|
public CacheHeaderPipeline(ICacheableSpecification cacheableSpecification)
|
|
{
|
|
_cacheableSpecification = cacheableSpecification;
|
|
}
|
|
|
|
public int Order => 0;
|
|
|
|
public void Register(IPipelines pipelines)
|
|
{
|
|
pipelines.AfterRequest.AddItemToStartOfPipeline(Handle);
|
|
}
|
|
|
|
private void Handle(NancyContext context)
|
|
{
|
|
if (context.Request.Method == "OPTIONS")
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (_cacheableSpecification.IsCacheable(context))
|
|
{
|
|
context.Response.Headers.EnableCache();
|
|
}
|
|
else
|
|
{
|
|
context.Response.Headers.DisableCache();
|
|
}
|
|
}
|
|
}
|
|
}
|