Accept headers and string path in Zotero.Utilities.Internal.saveURI()
This commit is contained in:
parent
3ff6626c12
commit
2b00a53e02
1 changed files with 13 additions and 9 deletions
|
@ -307,21 +307,25 @@ Zotero.Utilities.Internal = {
|
||||||
/**
|
/**
|
||||||
* saveURI wrapper function
|
* saveURI wrapper function
|
||||||
* @param {nsIWebBrowserPersist} nsIWebBrowserPersist
|
* @param {nsIWebBrowserPersist} nsIWebBrowserPersist
|
||||||
* @param {nsIURI} source URL
|
* @param {nsIURI} uri URL
|
||||||
* @param {nsISupports} target file
|
* @param {nsIFile|string path} target file
|
||||||
|
* @param {Object} [headers]
|
||||||
*/
|
*/
|
||||||
saveURI: function (wbp, source, target) {
|
saveURI: function (wbp, uri, target, headers) {
|
||||||
// Handle gzip encoding
|
// Handle gzip encoding
|
||||||
wbp.persistFlags |= Ci.nsIWebBrowserPersist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
|
wbp.persistFlags |= Ci.nsIWebBrowserPersist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
|
||||||
|
|
||||||
// Firefox 35 and below
|
if (typeof uri == 'string') {
|
||||||
try {
|
uri = Services.io.newURI(uri, null, null);
|
||||||
wbp.saveURI(source, null, null, null, null, target, null);
|
|
||||||
}
|
}
|
||||||
// Firefox 36+ needs one more parameter
|
|
||||||
catch (e if e.name === "NS_ERROR_XPC_NOT_ENOUGH_ARGS") {
|
target = Zotero.File.pathToFile(target);
|
||||||
wbp.saveURI(source, null, null, null, null, null, target, null);
|
|
||||||
|
if (headers) {
|
||||||
|
headers = Object.keys(headers).map(x => x + ": " + headers[x]).join("\r\n") + "\r\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wbp.saveURI(uri, null, null, null, null, headers, target, null);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue