2013-08-20 02:31:26 +00:00
|
|
|
using System;
|
|
|
|
using Nancy;
|
2013-08-20 05:53:18 +00:00
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2014-12-02 06:26:25 +00:00
|
|
|
using NzbDrone.Common.Extensions;
|
2013-08-20 02:31:26 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Api.Frontend
|
|
|
|
{
|
2013-08-20 05:53:18 +00:00
|
|
|
public interface ICacheableSpecification
|
2013-08-20 02:31:26 +00:00
|
|
|
{
|
2013-08-20 05:53:18 +00:00
|
|
|
bool IsCacheable(NancyContext context);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class CacheableSpecification : ICacheableSpecification
|
|
|
|
{
|
|
|
|
public bool IsCacheable(NancyContext context)
|
2013-08-20 02:31:26 +00:00
|
|
|
{
|
2018-04-21 04:59:31 +00:00
|
|
|
if (!RuntimeInfo.IsProduction)
|
2013-08-21 06:28:41 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-31 07:40:23 +00:00
|
|
|
if (((DynamicDictionary)context.Request.Query).ContainsKey("h")) return true;
|
2013-08-20 05:53:18 +00:00
|
|
|
|
2014-07-21 14:33:52 +00:00
|
|
|
if (context.Request.Path.StartsWith("/api", StringComparison.CurrentCultureIgnoreCase))
|
|
|
|
{
|
|
|
|
if (context.Request.Path.ContainsIgnoreCase("/MediaCover")) return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-20 05:53:18 +00:00
|
|
|
if (context.Request.Path.StartsWith("/signalr", StringComparison.CurrentCultureIgnoreCase)) return false;
|
2013-11-21 06:04:15 +00:00
|
|
|
if (context.Request.Path.EndsWith("main.js")) return false;
|
2014-05-11 01:31:07 +00:00
|
|
|
if (context.Request.Path.StartsWith("/feed", StringComparison.CurrentCultureIgnoreCase)) return false;
|
2013-08-20 02:31:26 +00:00
|
|
|
|
2013-10-08 02:37:02 +00:00
|
|
|
if (context.Request.Path.StartsWith("/log", StringComparison.CurrentCultureIgnoreCase) &&
|
|
|
|
context.Request.Path.EndsWith(".txt", StringComparison.CurrentCultureIgnoreCase))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-20 05:53:18 +00:00
|
|
|
if (context.Response != null)
|
|
|
|
{
|
|
|
|
if (context.Response.ContentType.Contains("text/html")) return false;
|
|
|
|
}
|
2013-08-20 02:31:26 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2018-04-21 04:59:31 +00:00
|
|
|
}
|