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
This commit is contained in:
Thomas Wisniewski 2016-07-11 14:27:36 -04:00
parent 97a6dfcff5
commit 291ec7772c
4 changed files with 19 additions and 11 deletions

View File

@ -776,7 +776,11 @@ BlobImplBase::GetSendInfo(nsIInputStream** aBody, uint64_t* aContentLength,
nsAutoString contentType;
GetType(contentType);
if (contentType.IsEmpty()) {
aContentType.SetIsVoid(true);
} else {
CopyUTF16toUTF8(contentType, aContentType);
}
aCharset.Truncate();

View File

@ -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<RequestBody>
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="));

View File

@ -808,9 +808,15 @@ HttpBaseChannel::ExplicitSetUploadStream(nsIInputStream *aStream,
contentLengthStr.AppendInt(aContentLength);
SetRequestHeader(NS_LITERAL_CSTRING("Content-Length"), contentLengthStr,
false);
if (!aContentType.IsVoid()) {
if (aContentType.IsEmpty()) {
SetEmptyRequestHeader(NS_LITERAL_CSTRING("Content-Type"));
} else {
SetRequestHeader(NS_LITERAL_CSTRING("Content-Type"), aContentType,
false);
}
}
}
mUploadStreamHasHeaders = aStreamHasHeaders;
mUploadStream = aStream;

View File

@ -1,5 +0,0 @@
[setrequestheader-content-type.htm]
type: testharness
[XMLHttpRequest: setRequestHeader() - Content-Type header ()]
expected: FAIL