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.
Lidarr/src/Lidarr.Http/Middleware/CacheableSpecification.cs

70 lines
1.8 KiB

using System;
using Microsoft.AspNetCore.Http;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Extensions;
namespace Lidarr.Http.Middleware
{
public interface ICacheableSpecification
{
bool IsCacheable(HttpRequest request);
}
public class CacheableSpecification : ICacheableSpecification
{
public bool IsCacheable(HttpRequest request)
{
if (!RuntimeInfo.IsProduction)
{
return false;
}
if (request.Query.ContainsKey("h"))
{
return true;
}
if (request.Path.StartsWithSegments("/api", StringComparison.CurrentCultureIgnoreCase))
{
if (request.Path.ToString().ContainsIgnoreCase("/MediaCover"))
{
return true;
}
return false;
}
if (request.Path.StartsWithSegments("/signalr", StringComparison.CurrentCultureIgnoreCase))
{
return false;
}
var path = request.Path.Value ?? "";
if (path.EndsWith("/index.js"))
{
return false;
}
if (path.EndsWith("/initialize.json"))
{
return false;
}
if (path.StartsWith("/feed", StringComparison.CurrentCultureIgnoreCase))
{
return false;
}
if ((path.StartsWith("/logfile", StringComparison.CurrentCultureIgnoreCase) ||
path.StartsWith("/updatelogfile", StringComparison.CurrentCultureIgnoreCase)) &&
path.EndsWith(".txt", StringComparison.CurrentCultureIgnoreCase))
{
return false;
}
return true;
}
}
}