From 6c0743a70dfa11bf8603243b27de2aaecb102962 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 3 Dec 2015 11:57:23 -0500 Subject: [PATCH] update caching headers --- .../HttpServer/HttpResultFactory.cs | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs index 080441dda4..4252d7aa82 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs @@ -114,6 +114,12 @@ namespace MediaBrowser.Server.Implementations.HttpServer /// result public object GetOptimizedResult(IRequest requestContext, T result, IDictionary responseHeaders = null) where T : class + { + return GetOptimizedResultInternal(requestContext, result, true, responseHeaders); + } + + private object GetOptimizedResultInternal(IRequest requestContext, T result, bool addCachePrevention, IDictionary responseHeaders = null) + where T : class { if (result == null) { @@ -122,20 +128,27 @@ namespace MediaBrowser.Server.Implementations.HttpServer var optimizedResult = requestContext.ToOptimizedResult(result); - if (responseHeaders != null) + if (responseHeaders == null) { - // Apply headers - var hasOptions = optimizedResult as IHasOptions; + responseHeaders = new Dictionary(StringComparer.OrdinalIgnoreCase); + } - if (hasOptions != null) - { - AddResponseHeaders(hasOptions, responseHeaders); - } + if (addCachePrevention) + { + responseHeaders["Expires"] = "-1"; + } + + // Apply headers + var hasOptions = optimizedResult as IHasOptions; + + if (hasOptions != null) + { + AddResponseHeaders(hasOptions, responseHeaders); } return optimizedResult; } - + /// /// Gets the optimized result using cache. /// @@ -166,7 +179,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer if (responseHeaders == null) { - responseHeaders = new Dictionary(); + responseHeaders = new Dictionary(StringComparer.OrdinalIgnoreCase); } // See if the result is already cached in the browser @@ -177,7 +190,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer return result; } - return GetOptimizedResult(requestContext, factoryFn(), responseHeaders); + return GetOptimizedResultInternal(requestContext, factoryFn(), false, responseHeaders); } /// @@ -209,7 +222,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer if (responseHeaders == null) { - responseHeaders = new Dictionary(); + responseHeaders = new Dictionary(StringComparer.OrdinalIgnoreCase); } // See if the result is already cached in the browser @@ -363,7 +376,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer public object GetStaticResult(IRequest requestContext, StaticResultOptions options) { var cacheKey = options.CacheKey; - options.ResponseHeaders = options.ResponseHeaders ?? new Dictionary(); + options.ResponseHeaders = options.ResponseHeaders ?? new Dictionary(StringComparer.OrdinalIgnoreCase); var contentType = options.ContentType; if (cacheKey == Guid.Empty)