mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
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:
parent
97a6dfcff5
commit
291ec7772c
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user