Bug 1437360 - do not attempt to parse XHRs as XML if content-length=0, to prevent logging "no root element found" errors; r=smaug

do not attempt to parse XHRs as XML if content-length=0, to prevent logging "no root element found" errors

Differential Revision: https://phabricator.services.mozilla.com/D23444

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Thomas Wisniewski 2019-03-20 15:43:31 +00:00
Родитель 5ffebc7b88
Коммит 13eb2f8827
3 изменённых файлов: 14 добавлений и 2 удалений

Просмотреть файл

@ -1,6 +1,7 @@
function handleRequest(request, response)
{
let [status, statusText, body] = request.queryString.split("&");
let [status, statusText, encodedBody] = request.queryString.split("&");
let body = decodeURIComponent(encodedBody);
response.setStatusLine(request.httpVersion, status, statusText);
response.setHeader("Content-Type", "text/xml", false);
response.setHeader("Content-Length", "" + body.length, false);

Просмотреть файл

@ -19,6 +19,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=884693
const SERVER_URL = "http://mochi.test:8888/tests/dom/base/test/chrome/bug884693.sjs";
const INVALID_XML = "InvalidXML";
const XML_WITHOUT_ROOT = "<?xml version='1.0'?>";
let consoleService = Cc["@mozilla.org/consoleservice;1"].
getService(Ci.nsIConsoleService)
@ -63,7 +64,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=884693
then(() => { return runTest(205, "Reset Content", INVALID_XML, "", []); }).
then(() => { return runTest(304, "Not modified", "", "", []); }).
then(() => { return runTest(304, "Not modified", INVALID_XML, "", []); }).
then(() => { return runTest(200, "OK", "", "", ["no root element found"]); }).
then(() => { return runTest(200, "OK", "", "", []); }).
then(() => { return runTest(200, "OK", XML_WITHOUT_ROOT, XML_WITHOUT_ROOT, ["no root element found"]); }).
then(() => { return runTest(200, "OK", INVALID_XML, INVALID_XML, ["syntax error"]); }).
then(SimpleTest.finish);

Просмотреть файл

@ -1888,6 +1888,15 @@ XMLHttpRequestMainThread::OnStartRequest(nsIRequest* request) {
!(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;
mWarnAboutSyncHtml = false;
if (parseBody && NS_SUCCEEDED(status)) {