2013-09-13 01:42:01 +03:00
|
|
|
using Nancy;
|
2013-08-20 08:53:18 +03:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|