You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.1 KiB
75 lines
2.1 KiB
using System;
|
|
using Microsoft.AspNetCore.Http;
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
namespace Lidarr.Http.Middleware
|
|
{
|
|
public interface ICacheableSpecification
|
|
{
|
|
bool IsCacheable(HttpContext context);
|
|
}
|
|
|
|
public class CacheableSpecification : ICacheableSpecification
|
|
{
|
|
public bool IsCacheable(HttpContext context)
|
|
{
|
|
if (!RuntimeInfo.IsProduction)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (context.Request.Query.ContainsKey("h"))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (context.Request.Path.StartsWithSegments("/api", StringComparison.CurrentCultureIgnoreCase))
|
|
{
|
|
if (context.Request.Path.ToString().ContainsIgnoreCase("/MediaCover"))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
if (context.Request.Path.StartsWithSegments("/signalr", StringComparison.CurrentCultureIgnoreCase))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (context.Request.Path.Value?.EndsWith("/index.js") ?? false)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (context.Request.Path.Value?.EndsWith("/initialize.js") ?? false)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (context.Request.Path.StartsWithSegments("/feed", StringComparison.CurrentCultureIgnoreCase))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (context.Request.Path.StartsWithSegments("/log", StringComparison.CurrentCultureIgnoreCase) &&
|
|
(context.Request.Path.Value?.EndsWith(".txt", StringComparison.CurrentCultureIgnoreCase) ?? false))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (context.Response != null)
|
|
{
|
|
if (context.Response.ContentType?.Contains("text/html") ?? false || context.Response.StatusCode >= 400)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|