From 0d3d9044a6a720a6932ada55429f0a5d6f74e4e8 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Thu, 27 Aug 2015 10:14:03 -0400 Subject: [PATCH] Bug 815299 - Part 2: Accept empty HTTP headers in fetch; r=jdm --- dom/fetch/FetchDriver.cpp | 6 +++++- dom/workers/test/serviceworkers/fetch/fetch_tests.js | 12 ++++++++++++ .../test/serviceworkers/fetch_event_worker.js | 9 +++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/dom/fetch/FetchDriver.cpp b/dom/fetch/FetchDriver.cpp index 46ae6d3de95a..81d91b7b958f 100644 --- a/dom/fetch/FetchDriver.cpp +++ b/dom/fetch/FetchDriver.cpp @@ -477,7 +477,11 @@ FetchDriver::HttpFetch(bool aCORSFlag, bool aCORSPreflightFlag, bool aAuthentica nsAutoTArray 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. diff --git a/dom/workers/test/serviceworkers/fetch/fetch_tests.js b/dom/workers/test/serviceworkers/fetch/fetch_tests.js index 841d586cc544..e1ab11047c1c 100644 --- a/dom/workers/test/serviceworkers/fetch/fetch_tests.js +++ b/dom/workers/test/serviceworkers/fetch/fetch_tests.js @@ -320,3 +320,15 @@ fetch(new Request('body-blob', {method: 'POST', body: new Blob(new String('my bo 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(); +}); diff --git a/dom/workers/test/serviceworkers/fetch_event_worker.js b/dom/workers/test/serviceworkers/fetch_event_worker.js index 87534893654f..5c13b6206549 100644 --- a/dom/workers/test/serviceworkers/fetch_event_worker.js +++ b/dom/workers/test/serviceworkers/fetch_event_worker.js @@ -274,4 +274,13 @@ onfetch = function(ev) { 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")); + } };