diff --git a/chrome/content/zotero/xpcom/cookieSandbox.js b/chrome/content/zotero/xpcom/cookieSandbox.js index b54d380697..e17a7423fe 100755 --- a/chrome/content/zotero/xpcom/cookieSandbox.js +++ b/chrome/content/zotero/xpcom/cookieSandbox.js @@ -31,8 +31,9 @@ * @param {String|nsIURI} uri URI of page to manage cookies for (cookies for domains that are not * subdomains of this URI are ignored) * @param {String} cookieData Cookies with which to initiate the sandbox + * @param {String} userAgent User agent to use for sandboxed requests */ -Zotero.CookieSandbox = function(browser, uri, cookieData) { +Zotero.CookieSandbox = function(browser, uri, cookieData, userAgent) { this._observerService = Components.classes["@mozilla.org/observer-service;1"]. getService(Components.interfaces.nsIObserverService); @@ -54,6 +55,8 @@ Zotero.CookieSandbox = function(browser, uri, cookieData) { } } + if(userAgent) this.userAgent = userAgent; + Zotero.CookieSandbox.Observer.register(); if(browser) { this.attachToBrowser(browser); @@ -206,6 +209,10 @@ Zotero.CookieSandbox.Observer = new function() { return; } + if(trackedBy.userAgent) { + channel.setRequestHeader("User-Agent", trackedBy.userAgent, false); + } + // add cookies to be sent to this domain channel.setRequestHeader("Cookie", trackedBy.cookieString, false); Zotero.debug("CookieSandbox: Added cookies for request to "+channelURI, 5); diff --git a/chrome/content/zotero/xpcom/server.js b/chrome/content/zotero/xpcom/server.js index 1d7867c6bd..172a86c460 100755 --- a/chrome/content/zotero/xpcom/server.js +++ b/chrome/content/zotero/xpcom/server.js @@ -361,9 +361,12 @@ Zotero.Server.DataListener.prototype._processEndpoint = function(method, postDat // pass to endpoint if((endpoint.init.length ? endpoint.init.length : endpoint.init.arity) === 3) { + const uaRe = /[\r\n]User-Agent: +([^\r\n]+)/i; + var m = uaRe.exec(this.header); var url = { "pathname":this.pathname, - "query":this.query ? Zotero.Server.decodeQueryString(this.query.substr(1)) : {} + "query":this.query ? Zotero.Server.decodeQueryString(this.query.substr(1)) : {}, + "userAgent":m && m[1] }; endpoint.init(url, decodedData, sendResponseCallback); diff --git a/chrome/content/zotero/xpcom/server_connector.js b/chrome/content/zotero/xpcom/server_connector.js index 644d764359..7875f677b1 100755 --- a/chrome/content/zotero/xpcom/server_connector.js +++ b/chrome/content/zotero/xpcom/server_connector.js @@ -98,7 +98,7 @@ Zotero.Server.Connector.Detect.prototype = { * @param {Object} data POST data or GET query string * @param {Function} sendResponseCallback function to send HTTP response */ - "init":function(data, sendResponseCallback) { + "init":function(url, data, sendResponseCallback) { this.sendResponse = sendResponseCallback; this._parsedPostData = data; @@ -115,7 +115,7 @@ Zotero.Server.Connector.Detect.prototype = { var pageShowCalled = false; var me = this; this._translate.setCookieSandbox(new Zotero.CookieSandbox(this._browser, - this._parsedPostData["uri"], this._parsedPostData["cookie"])); + this._parsedPostData["uri"], this._parsedPostData["cookie"], url.userAgent)); this._browser.addEventListener("DOMContentLoaded", function() { try { if(me._browser.contentDocument.location.href == "about:blank") return; @@ -283,7 +283,7 @@ Zotero.Server.Connector.SaveItem.prototype = { * @param {Object} data POST data or GET query string * @param {Function} sendResponseCallback function to send HTTP response */ - "init":function(data, sendResponseCallback) { + "init":function(url, data, sendResponseCallback) { // figure out where to save var libraryID = null; var collectionID = null; @@ -293,8 +293,8 @@ Zotero.Server.Connector.SaveItem.prototype = { var collection = zp.getSelectedCollection(); } catch(e) {} - var cookieSandbox = data["uri"] && data["cookie"] ? new Zotero.CookieSandbox(null, data["uri"], - data["cookie"]) : null; + var cookieSandbox = data["uri"] ? new Zotero.CookieSandbox(null, data["uri"], + data["cookie"] || "", url.userAgent) : null; // save items var itemSaver = new Zotero.Translate.ItemSaver(libraryID, @@ -339,12 +339,12 @@ Zotero.Server.Connector.SaveSnapshot.prototype = { * @param {String} data POST data or GET query string * @param {Function} sendResponseCallback function to send HTTP response */ - "init":function(data, sendResponseCallback) { + "init":function(url, data, sendResponseCallback) { Zotero.Server.Connector.Data[data["url"]] = ""+data["html"]+""; var browser = Zotero.Browser.createHiddenBrowser(); var pageShowCalled = false; - var cookieSandbox = new Zotero.CookieSandbox(browser, data["url"], data["cookie"]); + var cookieSandbox = new Zotero.CookieSandbox(browser, data["url"], data["cookie"], url.userAgent); browser.addEventListener("pageshow", function() { if(browser.contentDocument.location.href == "about:blank" || browser.contentDocument.readyState !== "complete") return;