Radarr/src/Radarr.Http/Middleware/CacheableSpecification.cs

67 lines
1.8 KiB
C#
Raw Normal View History

2021-10-21 20:04:19 +00:00
using System;
using Microsoft.AspNetCore.Http;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Extensions;
namespace Radarr.Http.Middleware
{
public interface ICacheableSpecification
{
bool IsCacheable(HttpRequest request);
2021-10-21 20:04:19 +00:00
}
public class CacheableSpecification : ICacheableSpecification
{
public bool IsCacheable(HttpRequest request)
2021-10-21 20:04:19 +00:00
{
if (!RuntimeInfo.IsProduction)
{
return false;
}
if (request.Query.ContainsKey("h"))
2021-10-21 20:04:19 +00:00
{
return true;
}
if (request.Path.StartsWithSegments("/api", StringComparison.CurrentCultureIgnoreCase))
2021-10-21 20:04:19 +00:00
{
if (request.Path.ToString().ContainsIgnoreCase("/MediaCover"))
2021-10-21 20:04:19 +00:00
{
return true;
}
return false;
}
if (request.Path.StartsWithSegments("/signalr", StringComparison.CurrentCultureIgnoreCase))
2021-10-21 20:04:19 +00:00
{
return false;
}
if (request.Path.Value?.EndsWith("/index.js") ?? false)
2021-10-21 20:04:19 +00:00
{
return false;
}
if (request.Path.Value?.EndsWith("/initialize.js") ?? false)
2021-10-21 20:04:19 +00:00
{
return false;
}
if (request.Path.StartsWithSegments("/feed", StringComparison.CurrentCultureIgnoreCase))
2021-10-21 20:04:19 +00:00
{
return false;
}
if (request.Path.StartsWithSegments("/log", StringComparison.CurrentCultureIgnoreCase) &&
(request.Path.Value?.EndsWith(".txt", StringComparison.CurrentCultureIgnoreCase) ?? false))
2021-10-21 20:04:19 +00:00
{
return false;
}
return true;
}
}
}