Bug 815299 - Part 2: Accept empty HTTP headers in fetch; r=jdm
☠☠ backed out by 73250801ff8f ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 27 Aug 2015 10:14:03 -0400
changeset 294051 3555d4b1ab1ec066327e69e509b8800af4c8903a
parent 294050 8a798c03d76c42b15025e94fb3cf36f1e20e1ff5
child 294052 0a2a9972b4c74b55a8d19ca8add2ff4baf84ace0
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,17 @@ 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();
+});
--- 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"));
+  }
 };