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