Bug 781782 part 1. Fix fetch code to not set a Content-Type header when it shouldn't. r=bkelly
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 28 Nov 2016 15:58:02 -0500
changeset 324473 60d9b4f5054439f892ecf5f524d2fdd188d793e6
parent 324472 670fef2c9a617f21f3e273a2d558be356da431d0
child 324474 9acaf2d4db150126a2670e6a1a284b3d7fcb73c1
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersbkelly
bugs781782
milestone53.0a1
Bug 781782 part 1. Fix fetch code to not set a Content-Type header when it shouldn't. r=bkelly
dom/fetch/Fetch.cpp
testing/web-platform/meta/fetch/api/basic/request-headers-worker.html.ini
testing/web-platform/meta/fetch/api/basic/request-headers.html.ini
--- a/dom/fetch/Fetch.cpp
+++ b/dom/fetch/Fetch.cpp
@@ -523,17 +523,19 @@ ExtractFromBlob(const Blob& aBlob,
 
   impl->GetInternalStream(aStream, rv);
   if (NS_WARN_IF(rv.Failed())) {
     return rv.StealNSResult();
   }
 
   nsAutoString type;
   impl->GetType(type);
-  aContentType = NS_ConvertUTF16toUTF8(type);
+  if (!type.IsEmpty()) {
+    CopyUTF16toUTF8(type, aContentType);
+  }
   return NS_OK;
 }
 
 nsresult
 ExtractFromFormData(FormData& aFormData,
                     nsIInputStream** aStream,
                     nsCString& aContentType,
                     uint64_t& aContentLength)
@@ -598,16 +600,17 @@ ExtractFromURLSearchParams(const URLSear
 
 nsresult
 ExtractByteStreamFromBody(const OwningArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams& aBodyInit,
                           nsIInputStream** aStream,
                           nsCString& aContentType,
                           uint64_t& aContentLength)
 {
   MOZ_ASSERT(aStream);
+  aContentType.SetIsVoid(true);
 
   if (aBodyInit.IsArrayBuffer()) {
     const ArrayBuffer& buf = aBodyInit.GetAsArrayBuffer();
     return ExtractFromArrayBuffer(buf, aStream, aContentLength);
   }
   if (aBodyInit.IsArrayBufferView()) {
     const ArrayBufferView& buf = aBodyInit.GetAsArrayBufferView();
     return ExtractFromArrayBufferView(buf, aStream, aContentLength);
@@ -637,16 +640,17 @@ ExtractByteStreamFromBody(const OwningAr
 nsresult
 ExtractByteStreamFromBody(const ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams& aBodyInit,
                           nsIInputStream** aStream,
                           nsCString& aContentType,
                           uint64_t& aContentLength)
 {
   MOZ_ASSERT(aStream);
   MOZ_ASSERT(!*aStream);
+  aContentType.SetIsVoid(true);
 
   if (aBodyInit.IsArrayBuffer()) {
     const ArrayBuffer& buf = aBodyInit.GetAsArrayBuffer();
     return ExtractFromArrayBuffer(buf, aStream, aContentLength);
   }
   if (aBodyInit.IsArrayBufferView()) {
     const ArrayBufferView& buf = aBodyInit.GetAsArrayBufferView();
     return ExtractFromArrayBufferView(buf, aStream, aContentLength);
--- a/testing/web-platform/meta/fetch/api/basic/request-headers-worker.html.ini
+++ b/testing/web-platform/meta/fetch/api/basic/request-headers-worker.html.ini
@@ -1,29 +1,5 @@
 [request-headers-worker.html]
   type: testharness
-  [Fetch with HEAD with body]
-    expected: FAIL
-
   [Fetch with POST with FormData body]
     expected: FAIL
-
-  [Fetch with POST with Blob body]
-    expected: FAIL
-
-  [Fetch with POST with ArrayBuffer body]
-    expected: FAIL
-
-  [Fetch with POST with Uint8Array body]
-    expected: FAIL
-
-  [Fetch with POST with Int8Array body]
-    expected: FAIL
-
-  [Fetch with POST with Float32Array body]
-    expected: FAIL
-
-  [Fetch with POST with Float64Array body]
-    expected: FAIL
-
-  [Fetch with POST with DataView body]
-    expected: FAIL
-
+    bug: https://github.com/whatwg/fetch/issues/422
--- a/testing/web-platform/meta/fetch/api/basic/request-headers.html.ini
+++ b/testing/web-platform/meta/fetch/api/basic/request-headers.html.ini
@@ -1,29 +1,5 @@
 [request-headers.html]
   type: testharness
-  [Fetch with HEAD with body]
-    expected: FAIL
-
   [Fetch with POST with FormData body]
     expected: FAIL
-
-  [Fetch with POST with Blob body]
-    expected: FAIL
-
-  [Fetch with POST with ArrayBuffer body]
-    expected: FAIL
-
-  [Fetch with POST with Uint8Array body]
-    expected: FAIL
-
-  [Fetch with POST with Int8Array body]
-    expected: FAIL
-
-  [Fetch with POST with Float32Array body]
-    expected: FAIL
-
-  [Fetch with POST with Float64Array body]
-    expected: FAIL
-
-  [Fetch with POST with DataView body]
-    expected: FAIL
-
+    bug: https://github.com/whatwg/fetch/issues/422