diff options
author | Raymond Hill <rhill@raymondhill.net> | 2014-11-21 10:05:59 -0200 |
---|---|---|
committer | Raymond Hill <rhill@raymondhill.net> | 2014-11-21 10:05:59 -0200 |
commit | 281dc7038e88461a6e579b33f1d134daf40a4440 (patch) | |
tree | f666e7eada098065194039dd6f475d1d7948d6be /src/js | |
parent | 33969e8b2e5a6d9c42ef06ba5d2bc0e37bca3e54 (diff) | |
download | uBlock-281dc7038e88461a6e579b33f1d134daf40a4440.zip uBlock-281dc7038e88461a6e579b33f1d134daf40a4440.tar.gz uBlock-281dc7038e88461a6e579b33f1d134daf40a4440.tar.bz2 |
this fixes #362
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/mirrors.js | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/js/mirrors.js b/src/js/mirrors.js index d68b91c..9efd17f 100644 --- a/src/js/mirrors.js +++ b/src/js/mirrors.js @@ -21,6 +21,7 @@ /* jshint bitwise: false */ /* global µBlock, YaMD5 */ + 'use strict'; /******************************************************************************/ @@ -202,23 +203,43 @@ var toUrlKey = function(url) { // Ref: http://www.iana.org/assignments/media-types/media-types.xhtml +// https://github.com/gorhill/uBlock/issues/362 +// +// Using http://dev.w3.org/2006/webapi/FileAPI/#enctype logic, at least it's +// something... It looks like this is what the browser should be doing with +// `data:` URI, but it's not happening, so i will do it manually for now. +// +// ... +// 5. If the "getting an encoding" steps above return failure, then set +// encoding to null. +// 6. If encoding is null, then set encoding to utf-8. + var extractMimeType = function(ctin) { var pos = ctin.indexOf(';'); - return pos === -1 ? ctin.trim() : ctin.slice(0, pos).trim(); + var type = pos === -1 ? ctin.trim() : ctin.slice(0, pos).trim(); + var charset = pos === -1 ? '' : ctin.slice(pos).trim(); + if ( charset !== '' ) { + return type + ';' + charset; + } + // http://en.wikipedia.org/wiki/Internet_media_type#List_of_common_media_types + if ( type.slice(0, 4) === 'text' || /^application\/[a-z-]+script$/.test(type) ) { + return type + ';charset=utf-8'; + } + return type; }; /******************************************************************************/ var metadataExists = function(urlKey) { return typeof urlKey === 'string' && - metadata.urlKeyToHashMap.hasOwnProperty(urlKey); + metadata.urlKeyToHashMap.hasOwnProperty(urlKey); }; /******************************************************************************/ var contentExists = function(hash) { return typeof hash === 'string' && - hashToContentMap.hasOwnProperty(hash); + hashToContentMap.hasOwnProperty(hash); }; /******************************************************************************/ @@ -362,6 +383,7 @@ var cacheAsset = function(url) { if ( this.status !== 200 ) { return; } + //console.log('headers for "%s" = %o', url, this.getAllResponseHeaders()); var mimeType = extractMimeType(this.getResponseHeader('Content-Type')); var uint8Buffer = new Uint8Array(this.response); var yamd5 = new YaMD5(); |