From b208097a8e4e3ae4e2f776d823ac4831320f887b Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 22 Mar 2013 17:04:38 -0400 Subject: [PATCH] options.requestObserver callback for Zotero.HTTP.promise() The callback receives the XMLHttpRequest object after the open() call. --- chrome/content/zotero/xpcom/http.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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;