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
|
|
|
|
{
|
2021-10-21 20:04:26 +00:00
|
|
|
bool IsCacheable(HttpRequest request);
|
2021-10-21 20:04:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public class CacheableSpecification : ICacheableSpecification
|
|
|
|
{
|
2021-10-21 20:04:26 +00:00
|
|
|
public bool IsCacheable(HttpRequest request)
|
2021-10-21 20:04:19 +00:00
|
|
|
{
|
|
|
|
if (!RuntimeInfo.IsProduction)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-21 20:04:26 +00:00
|
|
|
if (request.Query.ContainsKey("h"))
|
2021-10-21 20:04:19 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-10-21 20:04:26 +00:00
|
|
|
if (request.Path.StartsWithSegments("/api", StringComparison.CurrentCultureIgnoreCase))
|
2021-10-21 20:04:19 +00:00
|
|
|
{
|
2021-10-21 20:04:26 +00:00
|
|
|
if (request.Path.ToString().ContainsIgnoreCase("/MediaCover"))
|
2021-10-21 20:04:19 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-21 20:04:26 +00:00
|
|
|
if (request.Path.StartsWithSegments("/signalr", StringComparison.CurrentCultureIgnoreCase))
|
2021-10-21 20:04:19 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-21 20:04:26 +00:00
|
|
|
if (request.Path.Value?.EndsWith("/index.js") ?? false)
|
2021-10-21 20:04:19 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-21 20:04:26 +00:00
|
|
|
if (request.Path.Value?.EndsWith("/initialize.js") ?? false)
|
2021-10-21 20:04:19 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-21 20:04:26 +00:00
|
|
|
if (request.Path.StartsWithSegments("/feed", StringComparison.CurrentCultureIgnoreCase))
|
2021-10-21 20:04:19 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-21 20:04:26 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|