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`.
This commit is contained in:
parent
e935001586
commit
bb1cbdff26
1 changed files with 13 additions and 9 deletions
|
@ -174,8 +174,13 @@ Zotero.HTTP = new function() {
|
||||||
channel.forceAllowThirdPartyCookie = true;
|
channel.forceAllowThirdPartyCookie = true;
|
||||||
|
|
||||||
// Set charset
|
// 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) {
|
if (options.responseCharset) {
|
||||||
channel.contentCharset = responseCharset;
|
xmlhttp.overrideMimeType(`text/plain; charset=${responseCharset}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable caching if requested
|
// Disable caching if requested
|
||||||
|
@ -342,9 +347,9 @@ Zotero.HTTP = new function() {
|
||||||
channel.QueryInterface(Components.interfaces.nsIHttpChannelInternal);
|
channel.QueryInterface(Components.interfaces.nsIHttpChannelInternal);
|
||||||
channel.forceAllowThirdPartyCookie = true;
|
channel.forceAllowThirdPartyCookie = true;
|
||||||
|
|
||||||
// Set charset
|
// Set charset -- see note in request() above
|
||||||
if (responseCharset) {
|
if (responseCharset) {
|
||||||
channel.contentCharset = responseCharset;
|
xmlhttp.overrideMimeType(`text/plain; charset=${responseCharset}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set request headers
|
// Set request headers
|
||||||
|
@ -360,7 +365,7 @@ Zotero.HTTP = new function() {
|
||||||
var useMethodjit = Components.utils.methodjit;
|
var useMethodjit = Components.utils.methodjit;
|
||||||
/** @ignore */
|
/** @ignore */
|
||||||
xmlhttp.onreadystatechange = function() {
|
xmlhttp.onreadystatechange = function() {
|
||||||
_stateChange(xmlhttp, onDone, responseCharset);
|
_stateChange(xmlhttp, onDone);
|
||||||
};
|
};
|
||||||
|
|
||||||
if(cookieSandbox) cookieSandbox.attachToInterfaceRequestor(xmlhttp.getInterface(Components.interfaces.nsIInterfaceRequestor));
|
if(cookieSandbox) cookieSandbox.attachToInterfaceRequestor(xmlhttp.getInterface(Components.interfaces.nsIInterfaceRequestor));
|
||||||
|
@ -414,9 +419,9 @@ Zotero.HTTP = new function() {
|
||||||
channel.QueryInterface(Components.interfaces.nsIHttpChannelInternal);
|
channel.QueryInterface(Components.interfaces.nsIHttpChannelInternal);
|
||||||
channel.forceAllowThirdPartyCookie = true;
|
channel.forceAllowThirdPartyCookie = true;
|
||||||
|
|
||||||
// Set charset
|
// Set charset -- see note in request() above
|
||||||
if (responseCharset) {
|
if (responseCharset) {
|
||||||
channel.contentCharset = responseCharset;
|
xmlhttp.overrideMimeType(`text/plain; charset=${responseCharset}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (headers) {
|
if (headers) {
|
||||||
|
@ -444,7 +449,7 @@ Zotero.HTTP = new function() {
|
||||||
var useMethodjit = Components.utils.methodjit;
|
var useMethodjit = Components.utils.methodjit;
|
||||||
/** @ignore */
|
/** @ignore */
|
||||||
xmlhttp.onreadystatechange = function() {
|
xmlhttp.onreadystatechange = function() {
|
||||||
_stateChange(xmlhttp, onDone, responseCharset);
|
_stateChange(xmlhttp, onDone);
|
||||||
};
|
};
|
||||||
|
|
||||||
if(cookieSandbox) cookieSandbox.attachToInterfaceRequestor(xmlhttp.getInterface(Components.interfaces.nsIInterfaceRequestor));
|
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 {nsIXMLHttpRequest} xmlhttp XMLHttpRequest whose state just changed
|
||||||
* @param {Function} [callback] Callback for request completion
|
* @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
|
* @param {*} [data] Data to be passed back to callback as the second argument
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function _stateChange(xmlhttp, callback, responseCharset, data) {
|
function _stateChange(xmlhttp, callback, data) {
|
||||||
switch (xmlhttp.readyState){
|
switch (xmlhttp.readyState){
|
||||||
// Request not yet made
|
// Request not yet made
|
||||||
case 1:
|
case 1:
|
||||||
|
|
Loading…
Add table
Reference in a new issue