commit b208097a8e4e3ae4e2f776d823ac4831320f887b
parent 059906a11e62352e08371b420f3595374f734aed
Author: Dan Stillman <dstillman@zotero.org>
Date: Fri, 22 Mar 2013 17:04:38 -0400
options.requestObserver callback for Zotero.HTTP.promise()
The callback receives the XMLHttpRequest object after the open() call.
Diffstat:
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/chrome/content/zotero/xpcom/http.js b/chrome/content/zotero/xpcom/http.js
@@ -41,6 +41,7 @@ Zotero.HTTP = new function() {
* <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>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>responseCharset - The charset the response should be interpreted as</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"]
.createInstance();
// Prevent certificate/authentication dialogs from popping up
xmlhttp.mozBackgroundRequest = true;
xmlhttp.open(method, url, true);
+ // Pass the request to a callback
+ if (options && options.requestObserver) {
+ options.requestObserver(xmlhttp);
+ }
+
if (method == 'PUT') {
// Some servers (e.g., Jungle Disk DAV) return a 200 response code
// with Content-Length: 0, which triggers a "no element found" error
@@ -128,8 +136,6 @@ Zotero.HTTP = new function() {
xmlhttp.setRequestHeader(header, headers[header]);
}
- var deferred = Q.defer();
-
xmlhttp.onloadend = function() {
var status = xmlhttp.status;