From 59b6510302cbfa6e458ae4160dec8140779433ba Mon Sep 17 00:00:00 2001 From: Michael Layzell Date: Wed, 23 Sep 2015 12:09:14 -0400 Subject: [PATCH] Bug 1207233 - Don't provide a default content-type header if user calls XHR.setRequestHeader('Content-Type', ''), r=jduell --- dom/base/nsXMLHttpRequest.cpp | 3 +-- netwerk/protocol/http/HttpBaseChannel.cpp | 9 +++++++-- .../XMLHttpRequest/setrequestheader-content-type.htm.ini | 5 ----- 3 files changed, 8 insertions(+), 9 deletions(-) delete mode 100644 testing/web-platform/meta/XMLHttpRequest/setrequestheader-content-type.htm.ini diff --git a/dom/base/nsXMLHttpRequest.cpp b/dom/base/nsXMLHttpRequest.cpp index ffa4b097e238..fabadd85c4b9 100644 --- a/dom/base/nsXMLHttpRequest.cpp +++ b/dom/base/nsXMLHttpRequest.cpp @@ -2700,8 +2700,7 @@ nsXMLHttpRequest::Send(nsIVariant* aVariant, const Nullable& aBody) nsAutoCString contentType; if (NS_FAILED(httpChannel-> GetRequestHeader(NS_LITERAL_CSTRING("Content-Type"), - contentType)) || - contentType.IsEmpty()) { + contentType))) { contentType = defaultContentType; if (!charset.IsEmpty()) { diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp index 341daa10cda9..c6bc9d52180f 100644 --- a/netwerk/protocol/http/HttpBaseChannel.cpp +++ b/netwerk/protocol/http/HttpBaseChannel.cpp @@ -721,8 +721,13 @@ HttpBaseChannel::ExplicitSetUploadStream(nsIInputStream *aStream, 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; diff --git a/testing/web-platform/meta/XMLHttpRequest/setrequestheader-content-type.htm.ini b/testing/web-platform/meta/XMLHttpRequest/setrequestheader-content-type.htm.ini deleted file mode 100644 index 7aec61cd2d92..000000000000 --- 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 -