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

70 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;
}
var path = request.Path.Value ?? "";
if (path.EndsWith("/index.js"))
2021-10-21 20:04:19 +00:00
{
return false;
}
if (path.EndsWith("/initialize.js"))
2021-10-21 20:04:19 +00:00
{
return false;
}
if (path.StartsWith("/feed", StringComparison.CurrentCultureIgnoreCase))
2021-10-21 20:04:19 +00:00
{
return false;
}
if ((path.StartsWith("/logfile", StringComparison.CurrentCultureIgnoreCase) ||
path.StartsWith("/updatelogfile", StringComparison.CurrentCultureIgnoreCase)) &&
path.EndsWith(".txt", StringComparison.CurrentCultureIgnoreCase))
2021-10-21 20:04:19 +00:00
{
return false;
}
return true;
}
}
}