mirror of
https://github.com/Radarr/Radarr.git
synced 2024-10-05 15:47:20 +02:00
Fixed: UI not updating on upgrade
(cherry picked from commit d566c1efd42f9a94c524db311e8fa99bc6e0323f) (cherry picked from commit 4b0586bd3d1cca4682dee53cc5af5ef1fa66978e) (cherry picked from commit 5b2affcabbc38d7122b39d3290e2021fdb8afbcc)
This commit is contained in:
parent
8cad9600cc
commit
aca669defe
@ -1,4 +1,5 @@
|
||||
using System.Net;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
|
||||
@ -13,5 +14,19 @@ public void should_get_index_html()
|
||||
var text = new WebClient().DownloadString(RootUrl);
|
||||
text.Should().NotBeNullOrWhiteSpace();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void index_should_not_be_cached()
|
||||
{
|
||||
var client = new WebClient();
|
||||
_ = client.DownloadString(RootUrl);
|
||||
|
||||
var headers = client.ResponseHeaders;
|
||||
|
||||
headers.Get("Cache-Control").Split(',').Select(x => x.Trim())
|
||||
.Should().BeEquivalentTo("no-store, no-cache".Split(',').Select(x => x.Trim()));
|
||||
headers.Get("Pragma").Should().Be("no-cache");
|
||||
headers.Get("Expires").Should().Be("-1");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -193,6 +193,7 @@ public static string GetRemoteIP(this HttpRequest request)
|
||||
|
||||
public static void DisableCache(this IHeaderDictionary headers)
|
||||
{
|
||||
headers.Remove("Last-Modified");
|
||||
headers["Cache-Control"] = "no-cache, no-store";
|
||||
headers["Expires"] = "-1";
|
||||
headers["Pragma"] = "no-cache";
|
||||
|
@ -28,7 +28,7 @@ protected StaticResourceMapperBase(IDiskProvider diskProvider, Logger logger)
|
||||
|
||||
public abstract bool CanHandle(string resourceUrl);
|
||||
|
||||
public virtual IActionResult GetResponse(string resourceUrl)
|
||||
public IActionResult GetResponse(string resourceUrl)
|
||||
{
|
||||
var filePath = Map(resourceUrl);
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
using NLog;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using Radarr.Http.Extensions;
|
||||
using Radarr.Http.Frontend.Mappers;
|
||||
|
||||
namespace Radarr.Http.Frontend
|
||||
@ -36,6 +37,7 @@ public StaticResourceController(IConfigFileProvider configFileProvider,
|
||||
[HttpGet("login")]
|
||||
public IActionResult LoginPage()
|
||||
{
|
||||
Response.Headers.DisableCache();
|
||||
return PhysicalFile(_loginPath, "text/html");
|
||||
}
|
||||
|
||||
@ -62,7 +64,19 @@ private IActionResult MapResource(string path)
|
||||
|
||||
if (mapper != null)
|
||||
{
|
||||
return mapper.GetResponse(path) ?? NotFound();
|
||||
var result = mapper.GetResponse(path);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
if ((result as FileResult)?.ContentType == "text/html")
|
||||
{
|
||||
Response.Headers.DisableCache();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
_logger.Warn("Couldn't find handler for {0}", path);
|
||||
|
@ -19,7 +19,7 @@ public async Task InvokeAsync(HttpContext context)
|
||||
{
|
||||
if (context.Request.Method != "OPTIONS")
|
||||
{
|
||||
if (_cacheableSpecification.IsCacheable(context))
|
||||
if (_cacheableSpecification.IsCacheable(context.Request))
|
||||
{
|
||||
context.Response.Headers.EnableCache();
|
||||
}
|
||||
|
@ -7,26 +7,26 @@ namespace Radarr.Http.Middleware
|
||||
{
|
||||
public interface ICacheableSpecification
|
||||
{
|
||||
bool IsCacheable(HttpContext context);
|
||||
bool IsCacheable(HttpRequest request);
|
||||
}
|
||||
|
||||
public class CacheableSpecification : ICacheableSpecification
|
||||
{
|
||||
public bool IsCacheable(HttpContext context)
|
||||
public bool IsCacheable(HttpRequest request)
|
||||
{
|
||||
if (!RuntimeInfo.IsProduction)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (context.Request.Query.ContainsKey("h"))
|
||||
if (request.Query.ContainsKey("h"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (context.Request.Path.StartsWithSegments("/api", StringComparison.CurrentCultureIgnoreCase))
|
||||
if (request.Path.StartsWithSegments("/api", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
if (context.Request.Path.ToString().ContainsIgnoreCase("/MediaCover"))
|
||||
if (request.Path.ToString().ContainsIgnoreCase("/MediaCover"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -34,40 +34,32 @@ public bool IsCacheable(HttpContext context)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (context.Request.Path.StartsWithSegments("/signalr", StringComparison.CurrentCultureIgnoreCase))
|
||||
if (request.Path.StartsWithSegments("/signalr", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (context.Request.Path.Value?.EndsWith("/index.js") ?? false)
|
||||
if (request.Path.Value?.EndsWith("/index.js") ?? false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (context.Request.Path.Value?.EndsWith("/initialize.js") ?? false)
|
||||
if (request.Path.Value?.EndsWith("/initialize.js") ?? false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (context.Request.Path.StartsWithSegments("/feed", StringComparison.CurrentCultureIgnoreCase))
|
||||
if (request.Path.StartsWithSegments("/feed", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (context.Request.Path.StartsWithSegments("/log", StringComparison.CurrentCultureIgnoreCase) &&
|
||||
(context.Request.Path.Value?.EndsWith(".txt", StringComparison.CurrentCultureIgnoreCase) ?? false))
|
||||
if (request.Path.StartsWithSegments("/log", StringComparison.CurrentCultureIgnoreCase) &&
|
||||
(request.Path.Value?.EndsWith(".txt", StringComparison.CurrentCultureIgnoreCase) ?? false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (context.Response != null)
|
||||
{
|
||||
if (context.Response.ContentType?.Contains("text/html") ?? false || context.Response.StatusCode >= 400)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public IfModifiedMiddleware(RequestDelegate next, ICacheableSpecification cachea
|
||||
|
||||
public async Task InvokeAsync(HttpContext context)
|
||||
{
|
||||
if (_cacheableSpecification.IsCacheable(context) && context.Request.Headers["IfModifiedSince"].Any())
|
||||
if (_cacheableSpecification.IsCacheable(context.Request) && context.Request.Headers["IfModifiedSince"].Any())
|
||||
{
|
||||
context.Response.StatusCode = 304;
|
||||
context.Response.Headers.EnableCache();
|
||||
|
Loading…
Reference in New Issue
Block a user