options.requestObserver callback for Zotero.HTTP.promise()
The callback receives the XMLHttpRequest object after the open() call.
This commit is contained in:
parent
059906a11e
commit
b208097a8e
1 changed files with 8 additions and 2 deletions
|
@ -41,6 +41,7 @@ Zotero.HTTP = new function() {
|
||||||
* <li>debug - Log response text and status code</li>
|
* <li>debug - Log response text and status code</li>
|
||||||
* <li>dontCache - If set, specifies that the request should not be fulfilled from the cache</li>
|
* <li>dontCache - If set, specifies that the request should not be fulfilled from the cache</li>
|
||||||
* <li>headers - HTTP headers to include in the request</li>
|
* <li>headers - HTTP headers to include in the request</li>
|
||||||
|
* <li>requestObserver - Callback to receive XMLHttpRequest after open()</li>
|
||||||
* <li>responseType - The type of the response. See XHR 2 documentation for legal values</li>
|
* <li>responseType - The type of the response. See XHR 2 documentation for legal values</li>
|
||||||
* <li>responseCharset - The charset the response should be interpreted as</li>
|
* <li>responseCharset - The charset the response should be interpreted as</li>
|
||||||
* <li>successCodes - HTTP status codes that are considered successful</li>
|
* <li>successCodes - HTTP status codes that are considered successful</li>
|
||||||
|
@ -86,12 +87,19 @@ Zotero.HTTP = new function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var deferred = Q.defer();
|
||||||
|
|
||||||
var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
||||||
.createInstance();
|
.createInstance();
|
||||||
// Prevent certificate/authentication dialogs from popping up
|
// Prevent certificate/authentication dialogs from popping up
|
||||||
xmlhttp.mozBackgroundRequest = true;
|
xmlhttp.mozBackgroundRequest = true;
|
||||||
xmlhttp.open(method, url, true);
|
xmlhttp.open(method, url, true);
|
||||||
|
|
||||||
|
// Pass the request to a callback
|
||||||
|
if (options && options.requestObserver) {
|
||||||
|
options.requestObserver(xmlhttp);
|
||||||
|
}
|
||||||
|
|
||||||
if (method == 'PUT') {
|
if (method == 'PUT') {
|
||||||
// Some servers (e.g., Jungle Disk DAV) return a 200 response code
|
// Some servers (e.g., Jungle Disk DAV) return a 200 response code
|
||||||
// with Content-Length: 0, which triggers a "no element found" error
|
// with Content-Length: 0, which triggers a "no element found" error
|
||||||
|
@ -128,8 +136,6 @@ Zotero.HTTP = new function() {
|
||||||
xmlhttp.setRequestHeader(header, headers[header]);
|
xmlhttp.setRequestHeader(header, headers[header]);
|
||||||
}
|
}
|
||||||
|
|
||||||
var deferred = Q.defer();
|
|
||||||
|
|
||||||
xmlhttp.onloadend = function() {
|
xmlhttp.onloadend = function() {
|
||||||
var status = xmlhttp.status;
|
var status = xmlhttp.status;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue