New: Use ASP.NET Core instead of Nancy

(cherry picked from commit 58ddbcd77e17ef95ecfad4b746084ee9326116f3)
This commit is contained in:
ta264
2021-03-15 21:32:12 +00:00
parent 7d494f9743
commit dbdc527f2e
122 changed files with 2177 additions and 2838 deletions

View File

@@ -0,0 +1,74 @@
using System;
using Microsoft.AspNetCore.Http;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Extensions;
namespace Prowlarr.Http.Middleware
{
public interface ICacheableSpecification
{
bool IsCacheable(HttpContext context);
}
public class CacheableSpecification : ICacheableSpecification
{
public bool IsCacheable(HttpContext context)
{
if (!RuntimeInfo.IsProduction)
{
return false;
}
if (context.Request.Query.ContainsKey("h"))
{
return true;
}
if (context.Request.Path.StartsWithSegments("/api", StringComparison.CurrentCultureIgnoreCase))
{
if (context.Request.Path.ToString().ContainsIgnoreCase("/MediaCover"))
{
return true;
}
return false;
}
if (context.Request.Path.StartsWithSegments("/signalr", StringComparison.CurrentCultureIgnoreCase))
{
return false;
}
if (context.Request.Path.Equals("/index.js"))
{
return false;
}
if (context.Request.Path.Equals("/initialize.js"))
{
return false;
}
if (context.Request.Path.StartsWithSegments("/feed", StringComparison.CurrentCultureIgnoreCase))
{
return false;
}
if (context.Request.Path.StartsWithSegments("/log", StringComparison.CurrentCultureIgnoreCase) &&
context.Request.Path.ToString().EndsWith(".txt", StringComparison.CurrentCultureIgnoreCase))
{
return false;
}
if (context.Response != null)
{
if (context.Response.ContentType?.Contains("text/html") ?? false || context.Response.StatusCode >= 400)
{
return false;
}
}
return true;
}
}
}