mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-06 04:52:21 -07:00
(cherry picked from commit d566c1efd42f9a94c524db311e8fa99bc6e0323f) (cherry picked from commit 4b0586bd3d1cca4682dee53cc5af5ef1fa66978e)
66 lines
1.8 KiB
C#
66 lines
1.8 KiB
C#
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;
|
|
}
|
|
|
|
if (request.Path.Value?.EndsWith("/index.js") ?? false)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (request.Path.Value?.EndsWith("/initialize.js") ?? false)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (request.Path.StartsWithSegments("/feed", StringComparison.CurrentCultureIgnoreCase))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (request.Path.StartsWithSegments("/log", StringComparison.CurrentCultureIgnoreCase) &&
|
|
(request.Path.Value?.EndsWith(".txt", StringComparison.CurrentCultureIgnoreCase) ?? false))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|