mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-11 15:47:09 -07:00
38 lines
1,020 B
C#
38 lines
1,020 B
C#
using System;
|
|
using Nancy;
|
|
using Nancy.Bootstrapper;
|
|
using Lidarr.Http.Frontend;
|
|
|
|
namespace Lidarr.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((Action<NancyContext>) 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();
|
|
}
|
|
}
|
|
}
|
|
}
|