From 291ec7772c3c787fdf49da5045d05ab87dea0240 Mon Sep 17 00:00:00 2001 From: Thomas Wisniewski Date: Mon, 11 Jul 2016 14:27:36 -0400 Subject: [PATCH] Bug 1207233 - Part 1: Allow not sending a Content-Type header, or sending a blank string for it, and have XMLHttpRequest.setRequestHeader honor those possibilities. r=dragana --HG-- extra : rebase_source : f4063c85716f899545878f89fc7f2225ef95c7cd --- dom/base/File.cpp | 6 +++++- dom/xhr/XMLHttpRequestMainThread.cpp | 9 ++++++--- netwerk/protocol/http/HttpBaseChannel.cpp | 10 ++++++++-- .../setrequestheader-content-type.htm.ini | 5 ----- 4 files changed, 19 insertions(+), 11 deletions(-) delete mode 100644 testing/web-platform/meta/XMLHttpRequest/setrequestheader-content-type.htm.ini diff --git a/dom/base/File.cpp b/dom/base/File.cpp index 4371e70c618f..cc7f73fea18b 100644 --- a/dom/base/File.cpp +++ b/dom/base/File.cpp @@ -776,7 +776,11 @@ BlobImplBase::GetSendInfo(nsIInputStream** aBody, uint64_t* aContentLength, nsAutoString contentType; GetType(contentType); - CopyUTF16toUTF8(contentType, aContentType); + if (contentType.IsEmpty()) { + aContentType.SetIsVoid(true); + } else { + CopyUTF16toUTF8(contentType, aContentType); + } aCharset.Truncate(); diff --git a/dom/xhr/XMLHttpRequestMainThread.cpp b/dom/xhr/XMLHttpRequestMainThread.cpp index d6bc820d76b3..5a1d8c74e96f 100644 --- a/dom/xhr/XMLHttpRequestMainThread.cpp +++ b/dom/xhr/XMLHttpRequestMainThread.cpp @@ -2344,6 +2344,10 @@ XMLHttpRequestMainThread::GetRequestBody(nsIVariant* aVariant, nsACString& aContentType, nsACString& aCharset) { + // null the content type and charset by default, as per XHR spec step 4 + aContentType.SetIsVoid(true); + aCharset.SetIsVoid(true); + if (aVariant) { return GetRequestBodyInternal(aVariant, aResult, aContentLength, aContentType, aCharset); @@ -2512,11 +2516,10 @@ XMLHttpRequestMainThread::Send(nsIVariant* aVariant, const Nullable nsAutoCString contentType; if (NS_FAILED(httpChannel-> GetRequestHeader(NS_LITERAL_CSTRING("Content-Type"), - contentType)) || - contentType.IsEmpty()) { + contentType))) { contentType = defaultContentType; - if (!charset.IsEmpty()) { + if (!charset.IsEmpty() && !contentType.IsVoid()) { // If we are providing the default content type, then we also need to // provide a charset declaration. contentType.Append(NS_LITERAL_CSTRING(";charset=")); diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp index f9048034637a..72546daf7cd9 100644 --- a/netwerk/protocol/http/HttpBaseChannel.cpp +++ b/netwerk/protocol/http/HttpBaseChannel.cpp @@ -808,8 +808,14 @@ 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.IsVoid()) { + 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 -