diff --git a/toolkit/components/extensions/ext-webRequest.js b/toolkit/components/extensions/ext-webRequest.js index 6796d9c54ce..bd501928f7e 100644 --- a/toolkit/components/extensions/ext-webRequest.js +++ b/toolkit/components/extensions/ext-webRequest.js @@ -53,7 +53,7 @@ function WebRequestEventManager(context, eventName) { return; } - let optional = ["requestHeaders", "responseHeaders", "statusCode", "redirectUrl"]; + let optional = ["requestHeaders", "responseHeaders", "statusCode", "statusLine", "redirectUrl"]; for (let opt of optional) { if (opt in data) { data2[opt] = data[opt]; diff --git a/toolkit/components/extensions/test/mochitest/test_ext_webrequest.html b/toolkit/components/extensions/test/mochitest/test_ext_webrequest.html index 9105450afd2..b278241928b 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_webrequest.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_webrequest.html @@ -96,6 +96,20 @@ function backgroundScript() { return url.startsWith(BASE) || /^data:.*\bwebRequestTest\b/.test(url); } + let statuses = [ + {url: /_script_good\b/, code: 200, line: /^HTTP\/1.1 200 OK\b/i}, + {url: /\bredirection\b/, code: 302, line: /^HTTP\/1.1 302\b/}, + {url: /\bnonexistent_script_/, code: 404, line: /^HTTP\/1.1 404 Not Found\b/i}, + ]; + function checkStatus(details) { + for (let {url, code, line} of statuses) { + if (url.test(details.url)) { + browser.test.assertTrue(code === details.statusCode, `HTTP status code ${code} for ${details.url} (found ${details.statusCode})`); + browser.test.assertTrue(line.test(details.statusLine), `HTTP status line ${line} for ${details.url} (found ${details.statusLine})`); + } + } + } + function checkType(details) { let expected_type = "???"; if (details.url.indexOf("style") != -1) { @@ -302,6 +316,7 @@ function backgroundScript() { browser.test.assertEq(details.tabId, savedTabId, "correct tab ID"); checkType(details); + checkStatus(details); let id = frameIDs.get(details.url); browser.test.assertEq(id, details.frameId, "frame ID same in onBeforeRedirect as onBeforeRequest"); @@ -344,6 +359,7 @@ function backgroundScript() { } completedUrls[kind].add(details.url); } + checkStatus(details); } function onHeadersReceived(details) { diff --git a/toolkit/modules/addons/WebRequest.jsm b/toolkit/modules/addons/WebRequest.jsm index d6c08a82821..b73cfadaf7c 100644 --- a/toolkit/modules/addons/WebRequest.jsm +++ b/toolkit/modules/addons/WebRequest.jsm @@ -87,6 +87,20 @@ function parseExtra(extra, allowed) { return result; } +function mergeStatus(data, channel) { + try { + data.statusCode = channel.responseStatus; + let statusText = channel.responseStatusText; + let maj = {}; + let min = {}; + channel.QueryInterface(Ci.nsIHttpChannelInternal).getResponseVersion(maj, min); + data.statusLine = `HTTP/${maj.value}.${min.value} ${data.statusCode} ${statusText}`; + } catch (e) { + // NS_ERROR_NOT_AVAILABLE might be thrown. + Cu.reportError(e); + } +} + var HttpObserverManager; var ContentPolicyManager = { @@ -404,7 +418,7 @@ HttpObserverManager = { let responseHeaderNames; let includeStatus = kind === "headersReceived" || - kind === "onBeforeRedirect" || + kind === "onRedirect" || kind === "onStart" || kind === "onStop"; @@ -443,7 +457,7 @@ HttpObserverManager = { responseHeaderNames = data.responseHeaders.map(h => h.name); } if (includeStatus) { - data.statusCode = channel.responseStatus; + mergeStatus(data, channel); } let result = null;