commit bb1cbdff269383294f9525b8bed3e3cda03fe82b
parent e935001586dffafc35e2db76d89fee52d6c879bd
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 7 Nov 2017 16:51:29 -0500
Fix responseCharset parameter in HTTP methods
Setting `contentCharset` on the channel doesn't seem to work anymore, so
use `overrideMimeType()` instead like we do in the connector. As noted
in the comment, we should probably have a `responseContentType`
parameter instead, since that's what XHR actually allows. For the moment
we just use `text/plain`.
Diffstat:
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/chrome/content/zotero/xpcom/http.js b/chrome/content/zotero/xpcom/http.js
@@ -174,8 +174,13 @@ Zotero.HTTP = new function() {
channel.forceAllowThirdPartyCookie = true;
// Set charset
+ //
+ // This is the method used in the connector, but as noted there, this parameter is a
+ // legacy of XPCOM functionality (where it could be set on the nsIChannel, which
+ // doesn't seem to work anymore), and we should probably allow responseContentType to
+ // be set instead
if (options.responseCharset) {
- channel.contentCharset = responseCharset;
+ xmlhttp.overrideMimeType(`text/plain; charset=${responseCharset}`);
}
// Disable caching if requested
@@ -342,9 +347,9 @@ Zotero.HTTP = new function() {
channel.QueryInterface(Components.interfaces.nsIHttpChannelInternal);
channel.forceAllowThirdPartyCookie = true;
- // Set charset
+ // Set charset -- see note in request() above
if (responseCharset) {
- channel.contentCharset = responseCharset;
+ xmlhttp.overrideMimeType(`text/plain; charset=${responseCharset}`);
}
// Set request headers
@@ -360,7 +365,7 @@ Zotero.HTTP = new function() {
var useMethodjit = Components.utils.methodjit;
/** @ignore */
xmlhttp.onreadystatechange = function() {
- _stateChange(xmlhttp, onDone, responseCharset);
+ _stateChange(xmlhttp, onDone);
};
if(cookieSandbox) cookieSandbox.attachToInterfaceRequestor(xmlhttp.getInterface(Components.interfaces.nsIInterfaceRequestor));
@@ -414,9 +419,9 @@ Zotero.HTTP = new function() {
channel.QueryInterface(Components.interfaces.nsIHttpChannelInternal);
channel.forceAllowThirdPartyCookie = true;
- // Set charset
+ // Set charset -- see note in request() above
if (responseCharset) {
- channel.contentCharset = responseCharset;
+ xmlhttp.overrideMimeType(`text/plain; charset=${responseCharset}`);
}
if (headers) {
@@ -444,7 +449,7 @@ Zotero.HTTP = new function() {
var useMethodjit = Components.utils.methodjit;
/** @ignore */
xmlhttp.onreadystatechange = function() {
- _stateChange(xmlhttp, onDone, responseCharset);
+ _stateChange(xmlhttp, onDone);
};
if(cookieSandbox) cookieSandbox.attachToInterfaceRequestor(xmlhttp.getInterface(Components.interfaces.nsIInterfaceRequestor));
@@ -988,11 +993,10 @@ Zotero.HTTP = new function() {
*
* @param {nsIXMLHttpRequest} xmlhttp XMLHttpRequest whose state just changed
* @param {Function} [callback] Callback for request completion
- * @param {String} [responseCharset] Character set to force on the response
* @param {*} [data] Data to be passed back to callback as the second argument
* @private
*/
- function _stateChange(xmlhttp, callback, responseCharset, data) {
+ function _stateChange(xmlhttp, callback, data) {
switch (xmlhttp.readyState){
// Request not yet made
case 1: