Bug 1207233 - Don't provide a default content-type header if user calls XHR.setRequestHeader('Content-Type', ''), r=jduell
authorMichael Layzell <michael@thelayzells.com>
Wed, 23 Sep 2015 12:09:14 -0400
changeset 264242 b0d7f0fd067c181f0d7e51e59c9caadfa8664513
parent 264241 e22824771c7f6e72980fd6a2fee9bc49dfbc2c31
child 264243 0cecdec0f6e144c874e203744dc84c213ec057a5
push id65571
push usermichael@thelayzells.com
push dateThu, 24 Sep 2015 21:01:10 +0000
treeherdermozilla-inbound@b0d7f0fd067c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjduell
bugs1207233
milestone44.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 1207233 - Don't provide a default content-type header if user calls XHR.setRequestHeader('Content-Type', ''), r=jduell
dom/base/nsXMLHttpRequest.cpp
netwerk/protocol/http/HttpBaseChannel.cpp
testing/web-platform/meta/XMLHttpRequest/setrequestheader-content-type.htm.ini
--- a/dom/base/nsXMLHttpRequest.cpp
+++ b/dom/base/nsXMLHttpRequest.cpp
@@ -2695,18 +2695,17 @@ nsXMLHttpRequest::Send(nsIVariant* aVari
       net::InScriptableRange(size_u64) ? static_cast<int64_t>(size_u64) : -1;
 
     if (postDataStream) {
       // If no content type header was set by the client, we set it to
       // application/xml.
       nsAutoCString contentType;
       if (NS_FAILED(httpChannel->
                       GetRequestHeader(NS_LITERAL_CSTRING("Content-Type"),
-                                       contentType)) ||
-          contentType.IsEmpty()) {
+                                       contentType))) {
         contentType = defaultContentType;
 
         if (!charset.IsEmpty()) {
           // If we are providing the default content type, then we also need to
           // provide a charset declaration.
           contentType.Append(NS_LITERAL_CSTRING(";charset="));
           contentType.Append(charset);
         }
--- a/netwerk/protocol/http/HttpBaseChannel.cpp
+++ b/netwerk/protocol/http/HttpBaseChannel.cpp
@@ -716,18 +716,23 @@ HttpBaseChannel::ExplicitSetUploadStream
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!aStreamHasHeaders) {
     // SetRequestHeader propagates headers to chrome if HttpChannelChild
     nsAutoCString contentLengthStr;
     contentLengthStr.AppendInt(aContentLength);
     SetRequestHeader(NS_LITERAL_CSTRING("Content-Length"), contentLengthStr,
                      false);
-    SetRequestHeader(NS_LITERAL_CSTRING("Content-Type"), aContentType,
-                     false);
+
+    if (aContentType.IsEmpty()) {
+      SetEmptyRequestHeader(NS_LITERAL_CSTRING("Content-Type"));
+    } else {
+      SetRequestHeader(NS_LITERAL_CSTRING("Content-Type"), aContentType,
+                       false);
+    }
   }
 
   mUploadStreamHasHeaders = aStreamHasHeaders;
   mUploadStream = aStream;
   return NS_OK;
 }
 
 NS_IMETHODIMP
deleted file mode 100644
--- a/testing/web-platform/meta/XMLHttpRequest/setrequestheader-content-type.htm.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[setrequestheader-content-type.htm]
-  type: testharness
-  [XMLHttpRequest: setRequestHeader() - Content-Type header ()]
-    expected: FAIL
-