diff options
author | hackademix | 2018-07-09 19:32:24 +0200 |
---|---|---|
committer | hackademix | 2018-07-09 19:32:24 +0200 |
commit | 17a0426c3241bc1a67bf4b830f9d8cb01fcd895f (patch) | |
tree | b7eec2f6b44446838a8f001e3c1fd420877799b4 /src | |
parent | c6882356d3facb2a651b2bc637038cc290f8e768 (diff) | |
download | noscript-17a0426c3241bc1a67bf4b830f9d8cb01fcd895f.tar.gz noscript-17a0426c3241bc1a67bf4b830f9d8cb01fcd895f.tar.xz noscript-17a0426c3241bc1a67bf4b830f9d8cb01fcd895f.zip |
More specific dynamic script injection exceptions.
Diffstat (limited to 'src')
-rw-r--r-- | src/bg/RequestUtil.js | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/bg/RequestUtil.js b/src/bg/RequestUtil.js index 873f153..839ff28 100644 --- a/src/bg/RequestUtil.js +++ b/src/bg/RequestUtil.js @@ -1,8 +1,11 @@ 'use strict'; { let NULL = new Uint8Array(); - let xmlFeedOrImage = /^(?:(?:application|text)\/(?:(?:r(?:ss|df)|atom)\+)?xml(;|$))|image\//i; + let DEFAULT_CHARSET = "utf-8"; + let xmlFeedOrImage = /^(?:(?:application|text)\/(?:(?:r(?:ss|df)|atom)\+)xml(;|$))|image\//i; + let rawXml = /^(?:application|text)\/xml;/i; let brokenOnLoad = (async () => parseInt(await browser.runtime.getBrowserInfo().version) < 61); + let pendingRequests = new Map(); let cleanup = r => { @@ -35,15 +38,7 @@ var RequestUtil = { getContentMetaData(request) { - if (request.content) return request.content; - let {responseHeaders} = request; - let content = request.content = {}; - for (let h of responseHeaders) { - if (/^\s*Content-(Type|Disposition)\s*$/i.test(h.name)) { - content[h.name.split("-")[1].trim().toLowerCase()] = h.value; - } - } - return content; + return request.content || (request.content = new ContentMetaData(request)); }, async executeOnStart(request, details) { @@ -60,8 +55,9 @@ } let content = this.getContentMetaData(request); - debug(request.url, content.type); + debug(request.url, content.type, content.charset); if (xmlFeedOrImage.test(content.type) && !/\/svg\b/i.test(content.type)) return; + let disconnect = !(brokenOnLoad && rawXml.test(content.type)); let filter = browser.webRequest.filterResponseData(requestId); let buffer = []; @@ -73,18 +69,20 @@ for (let chunk of buffer) { filter.write(chunk); } - filter.disconnect(); + if (disconnect) filter.disconnect(); buffer = null; } }; if (brokenOnLoad) { filter.onstart = event => { + debug(`onstart ${request.url}`); filter.write(NULL); } } - filter.ondata = event => { + filter.ondata = event => { + if (first) { runAndFlush(); first = false; @@ -93,8 +91,10 @@ buffer.push(event.data); return; } + + debug(`ondata ${request.url}`); filter.write(event.data); - filter.disconnect(); + if (disconnect) filter.disconnect(); }; } |