mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1250987 - Make RequestInit.body nullable; r=bzbarsky
This commit is contained in:
parent
92a85ec88d
commit
12746db443
@ -370,7 +370,8 @@ Request::Constructor(const GlobalObject& aGlobal,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (aInit.mBody.WasPassed() || temporaryBody) {
|
||||
if ((aInit.mBody.WasPassed() && !aInit.mBody.Value().IsNull()) ||
|
||||
temporaryBody) {
|
||||
// HEAD and GET are not allowed to have a body.
|
||||
nsAutoCString method;
|
||||
request->GetMethod(method);
|
||||
@ -382,29 +383,34 @@ Request::Constructor(const GlobalObject& aGlobal,
|
||||
}
|
||||
|
||||
if (aInit.mBody.WasPassed()) {
|
||||
const OwningArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams& bodyInit = aInit.mBody.Value();
|
||||
nsCOMPtr<nsIInputStream> stream;
|
||||
nsAutoCString contentType;
|
||||
aRv = ExtractByteStreamFromBody(bodyInit,
|
||||
getter_AddRefs(stream), contentType);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
const Nullable<OwningArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams>& bodyInitNullable =
|
||||
aInit.mBody.Value();
|
||||
if (!bodyInitNullable.IsNull()) {
|
||||
const OwningArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams& bodyInit =
|
||||
bodyInitNullable.Value();
|
||||
nsCOMPtr<nsIInputStream> stream;
|
||||
nsAutoCString contentType;
|
||||
aRv = ExtractByteStreamFromBody(bodyInit,
|
||||
getter_AddRefs(stream), contentType);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
temporaryBody = stream;
|
||||
|
||||
if (!contentType.IsVoid() &&
|
||||
!requestHeaders->Has(NS_LITERAL_CSTRING("Content-Type"), aRv)) {
|
||||
requestHeaders->Append(NS_LITERAL_CSTRING("Content-Type"),
|
||||
contentType, aRv);
|
||||
}
|
||||
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
request->ClearCreatedByFetchEvent();
|
||||
request->SetBody(temporaryBody);
|
||||
}
|
||||
|
||||
temporaryBody = stream;
|
||||
|
||||
if (!contentType.IsVoid() &&
|
||||
!requestHeaders->Has(NS_LITERAL_CSTRING("Content-Type"), aRv)) {
|
||||
requestHeaders->Append(NS_LITERAL_CSTRING("Content-Type"),
|
||||
contentType, aRv);
|
||||
}
|
||||
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
request->ClearCreatedByFetchEvent();
|
||||
request->SetBody(temporaryBody);
|
||||
}
|
||||
|
||||
RefPtr<Request> domRequest = new Request(global, request);
|
||||
|
@ -38,7 +38,7 @@ Request implements Body;
|
||||
dictionary RequestInit {
|
||||
ByteString method;
|
||||
HeadersInit headers;
|
||||
BodyInit body;
|
||||
BodyInit? body;
|
||||
RequestMode mode;
|
||||
RequestCredentials credentials;
|
||||
RequestCache cache;
|
||||
|
@ -23,15 +23,23 @@
|
||||
}
|
||||
}, "Initialize Request with headers values");
|
||||
|
||||
function makeRequestInit(body, method) {
|
||||
return {"method": method, "body": body};
|
||||
}
|
||||
|
||||
function checkRequestInit(body, bodyType, expectedTextBody) {
|
||||
promise_test(function(test) {
|
||||
var request = new Request("", {"method": "POST", "body": body});
|
||||
assert_throws(new TypeError(),
|
||||
function() { new Request("", {"method": "GET", "body": body}); }
|
||||
);
|
||||
var request = new Request("", makeRequestInit(body, "POST"));
|
||||
if (body) {
|
||||
assert_throws(new TypeError(),
|
||||
function() { new Request("", makeRequestInit(body, "GET")); }
|
||||
);
|
||||
} else {
|
||||
new Request("", makeRequestInit(body, "GET")); // should not throw
|
||||
}
|
||||
var reqHeaders = request.headers;
|
||||
var mime = reqHeaders.get("Content-Type");
|
||||
assert_true(mime && mime.search(bodyType) > -1, "Content-Type header should be \"" + bodyType + "\", not \"" + mime + "\"");
|
||||
assert_true(!body || (mime && mime.search(bodyType) > -1), "Content-Type header should be \"" + bodyType + "\", not \"" + mime + "\"");
|
||||
return request.text().then(function(bodyAsText) {
|
||||
//not equals: cannot guess formData exact value
|
||||
assert_true( bodyAsText.search(expectedTextBody) > -1, "Retrieve and verify request body");
|
||||
@ -44,6 +52,8 @@
|
||||
formaData.append("name", "value");
|
||||
var usvString = "This is a USVString"
|
||||
|
||||
checkRequestInit(undefined, undefined, "");
|
||||
checkRequestInit(null, null, "");
|
||||
checkRequestInit(blob, "application/octet-binary", "This is a blob");
|
||||
checkRequestInit(formaData, "multipart/form-data", "name=\"name\"\r\n\r\nvalue");
|
||||
checkRequestInit(usvString, "text/plain;charset=UTF-8", "This is a USVString");
|
||||
|
Loading…
Reference in New Issue
Block a user