Bug 1109574 - Check for null body before setting bodyUsed in Request constructor. r=bkelly

This commit is contained in:
Nikhil Marathe 2014-12-23 02:25:17 -08:00
parent f0893ed316
commit 7d4e9dbdc2
2 changed files with 20 additions and 6 deletions

View File

@ -58,12 +58,17 @@ Request::Constructor(const GlobalObject& aGlobal,
if (aInput.IsRequest()) {
nsRefPtr<Request> inputReq = &aInput.GetAsRequest();
if (inputReq->BodyUsed()) {
aRv.ThrowTypeError(MSG_REQUEST_BODY_CONSUMED_ERROR);
return nullptr;
nsCOMPtr<nsIInputStream> body;
inputReq->GetBody(getter_AddRefs(body));
if (body) {
if (inputReq->BodyUsed()) {
aRv.ThrowTypeError(MSG_REQUEST_BODY_CONSUMED_ERROR);
return nullptr;
} else {
inputReq->SetBodyUsed();
}
}
inputReq->SetBodyUsed();
request = inputReq->GetInternalRequest();
} else {
request = new InternalRequest();

View File

@ -1,10 +1,8 @@
function ok(a, msg) {
dump("OK: " + !!a + " => " + a + " " + msg + "\n");
postMessage({type: 'status', status: !!a, msg: a + ": " + msg });
}
function is(a, b, msg) {
dump("IS: " + (a===b) + " => " + a + " | " + b + " " + msg + "\n");
postMessage({type: 'status', status: a === b, msg: a + " === " + b + ": " + msg });
}
@ -69,6 +67,16 @@ function testSimpleUrlParse() {
is(req.url, (new URL("/file.html", self.location.href)).href, "URL parser should be used to resolve Request URL");
}
// Bug 1109574 - Passing a Request with null body should keep bodyUsed unset.
function testBug1109574() {
var r1 = new Request("");
is(r1.bodyUsed, false, "Initial value of bodyUsed should be false");
var r2 = new Request(r1);
is(r1.bodyUsed, false, "Request with null body should not have bodyUsed set");
// This should succeed.
var r3 = new Request(r1);
}
function testMethod() {
var allowed = ["delete", "get", "head", "options", "post", "put"];
for (var i = 0; i < allowed.length; ++i) {
@ -205,6 +213,7 @@ onmessage = function() {
testSimpleUrlParse();
testUrlFragment();
testMethod();
testBug1109574();
Promise.resolve()
.then(testBodyCreation)