diff --git a/chrome/content/zotero/xpcom/http.js b/chrome/content/zotero/xpcom/http.js
index c551a1adeb..34aa3b822d 100644
--- a/chrome/content/zotero/xpcom/http.js
+++ b/chrome/content/zotero/xpcom/http.js
@@ -41,6 +41,7 @@ Zotero.HTTP = new function() {
*
debug - Log response text and status code
* dontCache - If set, specifies that the request should not be fulfilled from the cache
* headers - HTTP headers to include in the request
+ * requestObserver - Callback to receive XMLHttpRequest after open()
* responseType - The type of the response. See XHR 2 documentation for legal values
* responseCharset - The charset the response should be interpreted as
* successCodes - HTTP status codes that are considered successful
@@ -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;