From 0f52a5de226487bd82c59d12af09eba9d4c381f9 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sat, 13 Jul 2013 21:19:36 -0700 Subject: [PATCH] app.js is no longer cached. --- NzbDrone.Api/Frontend/IAddCacheHeaders.cs | 31 +++++++++++++++++++ .../Frontend/StaticResourceProvider.cs | 15 +++------ NzbDrone.Api/NzbDrone.Api.csproj | 1 + 3 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 NzbDrone.Api/Frontend/IAddCacheHeaders.cs diff --git a/NzbDrone.Api/Frontend/IAddCacheHeaders.cs b/NzbDrone.Api/Frontend/IAddCacheHeaders.cs new file mode 100644 index 000000000..e3bb01864 --- /dev/null +++ b/NzbDrone.Api/Frontend/IAddCacheHeaders.cs @@ -0,0 +1,31 @@ +using Nancy; +using NzbDrone.Api.Extensions; +using NzbDrone.Common.EnvironmentInfo; + +namespace NzbDrone.Api.Frontend +{ + public interface IAddCacheHeaders + { + void ToResponse(Request request, Response response); + } + + public class AddCacheHeaders : IAddCacheHeaders + { + public void ToResponse(Request request, Response response) + { + if (!RuntimeInfo.IsProduction) + { + response.Headers.DisableCache(); + return; + } + + if (request.Url.Path.ToLower() == "app.js") + { + response.Headers.DisableCache(); + return; + } + + response.Headers.EnableCache(); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Api/Frontend/StaticResourceProvider.cs b/NzbDrone.Api/Frontend/StaticResourceProvider.cs index b2e81fb1a..79ed9c811 100644 --- a/NzbDrone.Api/Frontend/StaticResourceProvider.cs +++ b/NzbDrone.Api/Frontend/StaticResourceProvider.cs @@ -19,14 +19,17 @@ namespace NzbDrone.Api.Frontend { private readonly IDiskProvider _diskProvider; private readonly IEnumerable _requestMappers; + private readonly IAddCacheHeaders _addCacheHeaders; private readonly Logger _logger; public StaticResourceProvider(IDiskProvider diskProvider, IEnumerable requestMappers, + IAddCacheHeaders addCacheHeaders, Logger logger) { _diskProvider = diskProvider; _requestMappers = requestMappers; + _addCacheHeaders = addCacheHeaders; _logger = logger; } @@ -48,18 +51,8 @@ namespace NzbDrone.Api.Frontend if (_diskProvider.FileExists(filePath)) { var response = new StreamResponse(() => File.OpenRead(filePath), MimeTypes.GetMimeType(filePath)); + _addCacheHeaders.ToResponse(context.Request, response); - if (RuntimeInfo.IsProduction) - { - response.Headers.EnableCache(); - } - - else - { - response.Headers.DisableCache(); - } - - //return response.CompressResponse(context.Request); return response; } diff --git a/NzbDrone.Api/NzbDrone.Api.csproj b/NzbDrone.Api/NzbDrone.Api.csproj index 896dcebfa..aaa3a3c8a 100644 --- a/NzbDrone.Api/NzbDrone.Api.csproj +++ b/NzbDrone.Api/NzbDrone.Api.csproj @@ -106,6 +106,7 @@ +