mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
34 lines
907 B
C#
34 lines
907 B
C#
|
using System;
|
||
|
using Nancy;
|
||
|
using Nancy.Bootstrapper;
|
||
|
using NzbDrone.Api.Frontend;
|
||
|
|
||
|
namespace NzbDrone.Api.Extensions.Pipelines
|
||
|
{
|
||
|
public class CacheHeaderPipeline : IRegisterNancyPipeline
|
||
|
{
|
||
|
private readonly ICacheableSpecification _cacheableSpecification;
|
||
|
|
||
|
public CacheHeaderPipeline(ICacheableSpecification cacheableSpecification)
|
||
|
{
|
||
|
_cacheableSpecification = cacheableSpecification;
|
||
|
}
|
||
|
|
||
|
public void Register(IPipelines pipelines)
|
||
|
{
|
||
|
pipelines.AfterRequest.AddItemToStartOfPipeline(Handle);
|
||
|
}
|
||
|
|
||
|
private void Handle(NancyContext context)
|
||
|
{
|
||
|
if (_cacheableSpecification.IsCacheable(context))
|
||
|
{
|
||
|
context.Response.Headers.EnableCache();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
context.Response.Headers.DisableCache();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|