From 2c36fbfeed622d1fbdbe72f009b169f22307f03f Mon Sep 17 00:00:00 2001 From: James South Date: Wed, 21 Jan 2015 15:01:33 +0000 Subject: [PATCH] Fix cache clearing breaking image returns Former-commit-id: 72b02f8ec749f0e553d8a922a20f011eca66df5c Former-commit-id: 8b4bc8842829047a47554d22ace90b2482bb2cfe --- .../HttpModules/ImageProcessingModule.cs | 19 ++++++++++++------- src/TestWebsites/MVC/Views/Web.config | 5 ++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs b/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs index f53a9ed25..01bb68828 100644 --- a/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs +++ b/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs @@ -346,9 +346,9 @@ namespace ImageProcessor.Web.HttpModules // Replace any presets in the querystring with the actual value. queryString = this.ReplacePresetsInQueryString(queryString); - + // Execute the handler which can change the querystring - queryString = this.CheckQuerystringHandler( queryString, request.RawUrl ); + queryString = this.CheckQuerystringHandler(queryString, request.RawUrl); // If the current service doesn't require a prefix, don't fetch it. // Let the static file handler take over. @@ -456,13 +456,14 @@ namespace ImageProcessor.Web.HttpModules context.Items[CachedResponseFileDependency] = new List { cachedPath }; } - if (!isNewOrUpdated) + string incomingEtag = context.Request.Headers["If-None-Match"]; + + if (incomingEtag != null && !isNewOrUpdated) { // Set the Content-Length header so the client doesn't wait for // content but keeps the connection open for other requests. context.Response.AddHeader("Content-Length", "0"); context.Response.StatusCode = (int)HttpStatusCode.NotModified; - context.Response.SuppressContent = true; if (isFileLocal) { @@ -560,8 +561,10 @@ namespace ImageProcessor.Web.HttpModules } } } + return queryString; } + /// /// Checks if there is a handler that changes the querystring and executes that handler. /// @@ -574,12 +577,14 @@ namespace ImageProcessor.Web.HttpModules /// /// The containing the updated querystring. /// - private string CheckQuerystringHandler(string queryString, string rawUrl) { + private string CheckQuerystringHandler(string queryString, string rawUrl) + { // Fire the process querystring event. ProcessQuerystringEventHandler handler = OnProcessQuerystring; - if ( handler != null ) { + if (handler != null) + { ProcessQueryStringEventArgs args = new ProcessQueryStringEventArgs { Querystring = queryString ?? string.Empty, RawUrl = rawUrl ?? string.Empty }; - queryString = handler( this, args ); + queryString = handler(this, args); } return queryString; diff --git a/src/TestWebsites/MVC/Views/Web.config b/src/TestWebsites/MVC/Views/Web.config index 3d9efc26a..c8101869a 100644 --- a/src/TestWebsites/MVC/Views/Web.config +++ b/src/TestWebsites/MVC/Views/Web.config @@ -45,10 +45,13 @@ - + + + +