Bug 815299 - Part 2: Accept empty HTTP headers in fetch; r=jdm
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 27 Aug 2015 10:14:03 -0400
changeset 294170 a9a32b845ba884ad926d2bbac572245dcb92b298
parent 294169 35502cb5d5b1f5fd83acaac08f0ca42ec189886e
child 294171 55d57fcbc791dc1341063c3d1ead6d832fdf150a
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs815299
milestone43.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 815299 - Part 2: Accept empty HTTP headers in fetch; r=jdm
dom/fetch/FetchDriver.cpp
dom/workers/test/serviceworkers/fetch/fetch_tests.js
dom/workers/test/serviceworkers/fetch_event_worker.js
--- a/dom/fetch/FetchDriver.cpp
+++ b/dom/fetch/FetchDriver.cpp
@@ -472,17 +472,21 @@ FetchDriver::HttpFetch(bool aCORSFlag, b
       FailWithNetworkError();
       return rv;
     }
 
     // Set the same headers.
     nsAutoTArray<InternalHeaders::Entry, 5> headers;
     mRequest->Headers()->GetEntries(headers);
     for (uint32_t i = 0; i < headers.Length(); ++i) {
-      httpChan->SetRequestHeader(headers[i].mName, headers[i].mValue, false /* merge */);
+      if (headers[i].mValue.IsEmpty()) {
+        httpChan->SetEmptyRequestHeader(headers[i].mName);
+      } else {
+        httpChan->SetRequestHeader(headers[i].mName, headers[i].mValue, false /* merge */);
+      }
     }
 
     // Step 2. Set the referrer.
     nsAutoString referrer;
     mRequest->GetReferrer(referrer);
     if (referrer.EqualsLiteral(kFETCH_CLIENT_REFERRER_STR)) {
       rv = nsContentUtils::SetFetchReferrerURIWithPolicy(mPrincipal,
                                                          mDocument,
--- a/dom/workers/test/serviceworkers/fetch/fetch_tests.js
+++ b/dom/workers/test/serviceworkers/fetch/fetch_tests.js
@@ -315,8 +315,20 @@ fetch(new Request('body-blob', {method: 
 
 ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'].forEach(function(method) {
   fetchXHRWithMethod('xhr-method-test.txt', method, function(xhr) {
     my_ok(xhr.status == 200, method + " load should be successful");
     my_ok(xhr.responseText == ("intercepted " + method), method + " load should have synthesized response");
     finish();
   });
 });
+
+expectAsyncResult();
+fetch(new Request('empty-header', {headers:{"emptyheader":""}}))
+.then(function(res) {
+  return res.text();
+}).then(function(body) {
+  my_ok(body == "emptyheader", "The empty header was observed in the fetch event");
+  finish();
+}, function(err) {
+  my_ok(false, "A promise was rejected with " + err);
+  finish();
+});
--- a/dom/workers/test/serviceworkers/fetch_event_worker.js
+++ b/dom/workers/test/serviceworkers/fetch_event_worker.js
@@ -269,9 +269,18 @@ onfetch = function(ev) {
 
     var url = 'http://example.com/tests/dom/security/test/cors/file_CrossSiteXHR_server.sjs?status=200';
     ev.respondWith(fetch(url, { mode: 'no-cors' }));
   }
 
   else if (ev.request.url.includes('xhr-method-test.txt')) {
     ev.respondWith(new Response('intercepted ' + ev.request.method));
   }
+
+  else if (ev.request.url.includes('empty-header')) {
+    if (!ev.request.headers.has("emptyheader") ||
+        ev.request.headers.get("emptyheader") !== "") {
+      ev.respondWith(Promise.reject());
+      return;
+    }
+    ev.respondWith(new Response("emptyheader"));
+  }
 };