No Issue - Do not parse or return body for XHRs with HEAD/CONNECT method or content-length=0

Based-on: m-c 1392220, 1437360
This commit is contained in:
Martok 2023-05-04 21:03:16 +02:00 committed by roytam1
commit 84eadbe3cf

View file

@ -602,6 +602,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.
@ -1915,13 +1921,19 @@ 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;
httpChannel->GetRequestMethod(method);
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"));
if (parseBody) {
// Do not try to parse documents if content-length = 0
int64_t contentLength;
if (NS_SUCCEEDED(mChannel->GetContentLength(&contentLength)) &&
contentLength == 0) {
parseBody = false;
}
}
mIsHtml = false;