Bug 1176988 - Patch 2 - Remove XHR cache bypass in cast of POST request. r=jdm
authorNikhil Marathe <nsm.nikhil@gmail.com>
Tue, 18 Aug 2015 11:31:27 -0700
changeset 259685 0af43571bfd874f79f5971aa6e3741b810f5fd36
parent 259684 728613ce6c705aac1aa66532b486ff04efca4db6
child 259686 dadd1a75446eb533f5622622658a54f37d6bf71a
push idunknown
push userunknown
push dateunknown
reviewersjdm
bugs1176988
milestone43.0a1
Bug 1176988 - Patch 2 - Remove XHR cache bypass in cast of POST request. r=jdm
dom/base/nsXMLHttpRequest.cpp
--- a/dom/base/nsXMLHttpRequest.cpp
+++ b/dom/base/nsXMLHttpRequest.cpp
@@ -2870,36 +2870,32 @@ nsXMLHttpRequest::Send(nsIVariant* aVari
   }
   else {
     AddLoadFlags(mChannel, nsIChannel::LOAD_EXPLICIT_CREDENTIALS);
   }
 
   NS_ASSERTION(listener != this,
                "Using an object as a listener that can't be exposed to JS");
 
-  // Bypass the network cache in cases where it makes no sense:
-  // POST responses are always unique, and we provide no API that would
-  // allow our consumers to specify a "cache key" to access old POST
-  // responses, so they are not worth caching.
-  if (method.EqualsLiteral("POST")) {
-    AddLoadFlags(mChannel,
-        nsIRequest::LOAD_BYPASS_CACHE | nsIRequest::INHIBIT_CACHING);
-  } else {
-    // When we are sync loading, we need to bypass the local cache when it would
-    // otherwise block us waiting for exclusive access to the cache.  If we don't
-    // do this, then we could dead lock in some cases (see bug 309424).
-    //
-    // Also don't block on the cache entry on async if it is busy - favoring parallelism
-    // over cache hit rate for xhr. This does not disable the cache everywhere -
-    // only in cases where more than one channel for the same URI is accessed
-    // simultanously.
-
-    AddLoadFlags(mChannel,
-                 nsICachingChannel::LOAD_BYPASS_LOCAL_CACHE_IF_BUSY);
-  }
+  // When we are sync loading, we need to bypass the local cache when it would
+  // otherwise block us waiting for exclusive access to the cache.  If we don't
+  // do this, then we could dead lock in some cases (see bug 309424).
+  //
+  // Also don't block on the cache entry on async if it is busy - favoring parallelism
+  // over cache hit rate for xhr. This does not disable the cache everywhere -
+  // only in cases where more than one channel for the same URI is accessed
+  // simultanously.
+
+  AddLoadFlags(mChannel,
+               nsICachingChannel::LOAD_BYPASS_LOCAL_CACHE_IF_BUSY);
+
+  // While it would be optimal to bypass the cache in case of POST requests
+  // since they are never cached, our ServiceWorker interception implementation
+  // on single-process systems is implemented via the HTTP cache, so DO NOT
+  // bypass the cache based on method!
 
   // Since we expect XML data, set the type hint accordingly
   // if the channel doesn't know any content type.
   // This means that we always try to parse local files as XML
   // ignoring return value, as this is not critical
   nsAutoCString contentType;
   if (NS_FAILED(mChannel->GetContentType(contentType)) ||
       contentType.IsEmpty() ||