diff options
author | hackademix | 2018-07-09 19:23:03 +0200 |
---|---|---|
committer | hackademix | 2018-07-09 19:29:23 +0200 |
commit | 7dfa2e640bcd5934831920139338b6bb656bcdc5 (patch) | |
tree | edf9555fce31ec8f8463d19b998196f4efeaa4c9 /src/lib/ContentMetaData.js | |
parent | 103324e5d2ea5ac2ea589a44b822a997ff503be3 (diff) | |
download | noscript-7dfa2e640bcd5934831920139338b6bb656bcdc5.tar.gz noscript-7dfa2e640bcd5934831920139338b6bb656bcdc5.tar.xz noscript-7dfa2e640bcd5934831920139338b6bb656bcdc5.zip |
Added two library files (one, lib/restricted.js, missing from rc8 tag) and version bump.
Diffstat (limited to 'src/lib/ContentMetaData.js')
-rw-r--r-- | src/lib/ContentMetaData.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/lib/ContentMetaData.js b/src/lib/ContentMetaData.js new file mode 100644 index 0000000..c60d75e --- /dev/null +++ b/src/lib/ContentMetaData.js @@ -0,0 +1,30 @@ +class ContentMetaData { + constructor(request, defaultCharset = "utf-8") { + this.defaultCharset = defaultCharset; + let {responseHeaders} = request; + for (let h of responseHeaders) { + if (/^\s*Content-(Type|Disposition)\s*$/i.test(h.name)) { + this[h.name.split("-")[1].trim().toLowerCase()] = h.value; + } + } + } + + get charset() { + let charset = this.defaultCharset; + if (this.type) { + let m = this.type.match(/;\s*charset\s*=\s*(\S+)/); + if (m) { + charset = m[1]; + } + } + Object.defineProperty(this, "charset", { value: charset, writable: false, configurable: true }) + } + + createDecoder() { + try { + return new TextDecoder(charset); + } catch (e) { + return new TextDecoder(this.defaultCharset); + } + } +}; |