Bug 1392220 - do not parse or return body for XHRs with HEAD or CONNECT method; r=baku

MozReview-Commit-ID: 40CxCiSFdjC

--HG--
extra : rebase_source : 663e09a83dd56aa7b6b76cbd3733cbffda1a7897
This commit is contained in:
Thomas Wisniewski 2017-09-09 15:34:48 -04:00
parent ff7b765b29
commit e469e3c48d
3 changed files with 16 additions and 32 deletions

View File

@ -412,7 +412,11 @@ fetch('interrupt.sjs')
['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'].forEach(function(method) {
fetchXHRWithMethod('xhr-method-test.txt', method, function(xhr) {
my_ok(xhr.status == 200, method + " load should be successful");
my_ok(xhr.responseText == ("intercepted " + method), method + " load should have synthesized response");
if (method === "HEAD") {
my_ok(xhr.responseText == "", method + "load should not have synthesized response");
} else {
my_ok(xhr.responseText == ("intercepted " + method), method + " load should have synthesized response");
}
finish();
});
});

View File

@ -624,6 +624,12 @@ XMLHttpRequestMainThread::GetResponseText(XMLHttpRequestStringSnapshot& aSnapsho
return;
}
// Main Fetch step 18 requires to ignore body for head/connect methods.
if (mRequestMethod.EqualsLiteral("HEAD") ||
mRequestMethod.EqualsLiteral("CONNECT")) {
return;
}
// We only decode text lazily if we're also parsing to a doc.
// Also, if we've decoded all current data already, then no need to decode
// more.
@ -2081,15 +2087,11 @@ XMLHttpRequestMainThread::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
}
// Set up responseXML
bool parseBody = mResponseType == XMLHttpRequestResponseType::_empty ||
mResponseType == XMLHttpRequestResponseType::Document;
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(mChannel));
if (parseBody && httpChannel) {
nsAutoCString method;
rv = httpChannel->GetRequestMethod(method);
MOZ_ASSERT(NS_SUCCEEDED(rv));
parseBody = !method.EqualsLiteral("HEAD");
}
// Note: Main Fetch step 18 requires to ignore body for head/connect methods.
bool parseBody = (mResponseType == XMLHttpRequestResponseType::_empty ||
mResponseType == XMLHttpRequestResponseType::Document) &&
!(mRequestMethod.EqualsLiteral("HEAD") ||
mRequestMethod.EqualsLiteral("CONNECT"));
mIsHtml = false;
mWarnAboutSyncHtml = false;

View File

@ -1,26 +1,4 @@
[data-uri.htm]
type: testharness
[XHR method GET with charset image/png]
expected: FAIL
[XHR method POST with charset text/plain]
expected: FAIL
[XHR method PUT with charset text/plain]
expected: FAIL
[XHR method DELETE with charset text/plain]
expected: FAIL
[XHR method HEAD with charset text/plain]
expected: FAIL
[XHR method UNICORN with charset text/plain]
expected: FAIL
[XHR method GET with MIME type image/png]
expected: FAIL
[XHR method HEAD with MIME type text/plain]
expected: FAIL