Bug 1126819 - Part 1: Respect the RequestInit.cache member in Request's constructor; r=nsm
authorEhsan Akhgari <ehsan@mozilla.com>
Sun, 22 Mar 2015 13:13:18 -0400
changeset 265450 c50fdfe5e786d4f5bb9a6004427f60c9fe7156f9
parent 265449 7e4412d1dcd6cd67571e22ebe9330269efa4a700
child 265451 f0afd7c244cc1a6f92cb40a4e97b5344bf7e83e1
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnsm
bugs1126819
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1126819 - Part 1: Respect the RequestInit.cache member in Request's constructor; r=nsm
dom/fetch/Request.cpp
dom/tests/mochitest/fetch/test_request.js
--- a/dom/fetch/Request.cpp
+++ b/dom/fetch/Request.cpp
@@ -77,16 +77,17 @@ Request::Constructor(const GlobalObject&
 
   request = request->GetRequestConstructorCopy(global, aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
   RequestMode fallbackMode = RequestMode::EndGuard_;
   RequestCredentials fallbackCredentials = RequestCredentials::EndGuard_;
+  RequestCache fallbackCache = RequestCache::EndGuard_;
   if (aInput.IsUSVString()) {
     nsString input;
     input.Assign(aInput.GetAsUSVString());
 
     nsString requestURL;
     if (NS_IsMainThread()) {
       nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(global);
       MOZ_ASSERT(window);
@@ -122,16 +123,17 @@ Request::Constructor(const GlobalObject&
       url->Stringify(requestURL, aRv);
       if (aRv.Failed()) {
         return nullptr;
       }
     }
     request->SetURL(NS_ConvertUTF16toUTF8(requestURL));
     fallbackMode = RequestMode::Cors;
     fallbackCredentials = RequestCredentials::Omit;
+    fallbackCache = RequestCache::Default;
   }
 
   // CORS-with-forced-preflight is not publicly exposed and should not be
   // considered a valid value.
   if (aInit.mMode.WasPassed() &&
       aInit.mMode.Value() == RequestMode::Cors_with_forced_preflight) {
     NS_NAMED_LITERAL_STRING(sourceDescription, "'mode' member of RequestInit");
     NS_NAMED_LITERAL_STRING(value, "cors-with-forced-preflight");
@@ -147,16 +149,22 @@ Request::Constructor(const GlobalObject&
   if (mode != RequestMode::EndGuard_) {
     request->SetMode(mode);
   }
 
   if (credentials != RequestCredentials::EndGuard_) {
     request->SetCredentialsMode(credentials);
   }
 
+  RequestCache cache = aInit.mCache.WasPassed() ?
+                       aInit.mCache.Value() : fallbackCache;
+  if (cache != RequestCache::EndGuard_) {
+    request->SetCacheMode(cache);
+  }
+
   // Request constructor step 14.
   if (aInit.mMethod.WasPassed()) {
     nsAutoCString method(aInit.mMethod.Value());
     nsAutoCString upperCaseMethod = method;
     ToUpperCase(upperCaseMethod);
 
     // Step 14.1. Disallow forbidden methods, and anything that is not a HTTP
     // token, since HTTP states that Method may be any of the defined values or
--- a/dom/tests/mochitest/fetch/test_request.js
+++ b/dom/tests/mochitest/fetch/test_request.js
@@ -2,48 +2,52 @@ function testDefaultCtor() {
   var req = new Request("");
   is(req.method, "GET", "Default Request method is GET");
   ok(req.headers instanceof Headers, "Request should have non-null Headers object");
   is(req.url, self.location.href, "URL should be resolved with entry settings object's API base URL");
   is(req.context, "fetch", "Default context is fetch.");
   is(req.referrer, "about:client", "Default referrer is `client` which serializes to about:client.");
   is(req.mode, "cors", "Request mode for string input is cors");
   is(req.credentials, "omit", "Default Request credentials is omit");
+  is(req.cache, "default", "Default Request cache is default");
 
   var req = new Request(req);
   is(req.method, "GET", "Default Request method is GET");
   ok(req.headers instanceof Headers, "Request should have non-null Headers object");
   is(req.url, self.location.href, "URL should be resolved with entry settings object's API base URL");
   is(req.context, "fetch", "Default context is fetch.");
   is(req.referrer, "about:client", "Default referrer is `client` which serializes to about:client.");
   is(req.mode, "cors", "Request mode string input is cors");
   is(req.credentials, "omit", "Default Request credentials is omit");
+  is(req.cache, "default", "Default Request cache is default");
 }
 
 function testClone() {
   var orig = new Request("./cloned_request.txt", {
               method: 'POST',
               headers: { "Content-Length": 5 },
               body: "Sample body",
               mode: "same-origin",
               credentials: "same-origin",
+              cache: "no-store",
             });
   var clone = orig.clone();
   ok(clone.method === "POST", "Request method is POST");
   ok(clone.headers instanceof Headers, "Request should have non-null Headers object");
 
   is(clone.headers.get('content-length'), "5", "Response content-length should be 5.");
   orig.headers.set('content-length', 6);
   is(clone.headers.get('content-length'), "5", "Request content-length should be 5.");
 
   ok(clone.url === (new URL("./cloned_request.txt", self.location.href)).href,
        "URL should be resolved with entry settings object's API base URL");
   ok(clone.referrer === "about:client", "Default referrer is `client` which serializes to about:client.");
   ok(clone.mode === "same-origin", "Request mode is same-origin");
   ok(clone.credentials === "same-origin", "Default credentials is same-origin");
+  ok(clone.cache === "no-store", "Default cache is no-store");
 
   ok(!orig.bodyUsed, "Original body is not consumed.");
   ok(!clone.bodyUsed, "Clone body is not consumed.");
 
   var origBody = null;
   var clone2 = null;
   return orig.text().then(function (body) {
     origBody = body;