Radarr/src/NzbDrone.Api/Frontend/CacheableSpecification.cs

50 lines
1.5 KiB
C#
Raw Normal View History

using System;
using Nancy;
2013-08-20 05:53:18 +00:00
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Api.Frontend
{
2013-08-20 05:53:18 +00:00
public interface ICacheableSpecification
{
2013-08-20 05:53:18 +00:00
bool IsCacheable(NancyContext context);
}
public class CacheableSpecification : ICacheableSpecification
{
public bool IsCacheable(NancyContext context)
{
2018-04-21 04:59:31 +00:00
if (!RuntimeInfo.IsProduction)
2013-08-21 06:28:41 +00:00
{
return false;
}
if (((DynamicDictionary)context.Request.Query).ContainsKey("h")) return true;
2013-08-20 05:53:18 +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;
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;
}
return true;
}
}
2018-04-21 04:59:31 +00:00
}