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
Родитель 97a6dfcff5
Коммит 291ec7772c
4 изменённых файлов: 19 добавлений и 11 удалений

Просмотреть файл

@ -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();

Просмотреть файл

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

Просмотреть файл

@ -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;

Просмотреть файл

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