commit 340f54c8b0f1da150e84a42463aa4b8c7df876e6
parent bf8e4eae285471fdd0a8bd0be10451b2d1d68141
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 16 Sep 2008 20:11:27 +0000
Add X-Zotero-Version header to HTTP requests to zotero.org
Diffstat:
3 files changed, 57 insertions(+), 0 deletions(-)
diff --git a/chrome/content/zotero/preferences/preferences.xul b/chrome/content/zotero/preferences/preferences.xul
@@ -49,6 +49,7 @@ To add a new preference:
<preference id="pref-statusBarIcon" name="extensions.zotero.statusBarIcon" type="int"/>
<preference id="pref-automaticScraperUpdates" name="extensions.zotero.automaticScraperUpdates" type="bool"/>
<preference id="pref-reportTranslationFailure" name="extensions.zotero.reportTranslationFailure" type="bool"/>
+ <preference id="pref-zoteroDotOrgVersionHeader" name="extensions.zotero.zoteroDotOrgVersionHeader" type="bool"/>
<preference id="pref-parseEndNoteMIMETypes" name="extensions.zotero.parseEndNoteMIMETypes" type="bool" onchange="Zotero.Ingester.MIMEHandler.init()"/>
<preference id="pref-automaticSnapshots" name="extensions.zotero.automaticSnapshots" type="bool"/>
<preference id="pref-downloadAssociatedFiles" name="extensions.zotero.downloadAssociatedFiles" type="bool"/>
@@ -118,6 +119,10 @@ To add a new preference:
</hbox>
<checkbox label="&zotero.preferences.reportTranslationFailure;" preference="pref-reportTranslationFailure"/>
+ <!-- TODO: localize -->
+ <checkbox label="Allow zotero.org to customize content based on current Zotero version"
+ tooltiptext="If enabled, the current Zotero version will be added to HTTP requests to zotero.org."
+ preference="pref-zoteroDotOrgVersionHeader"/>
<checkbox label="&zotero.preferences.parseRISRefer;" preference="pref-parseEndNoteMIMETypes"/>
<checkbox label="&zotero.preferences.automaticSnapshots;" preference="pref-automaticSnapshots"/>
<checkbox label="&zotero.preferences.downloadAssociatedFiles;" preference="pref-downloadAssociatedFiles"/>
diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js
@@ -215,6 +215,8 @@ var Zotero = new function(){
return;
}
+ Zotero.VersionHeader.init();
+
// Initialize keyboard shortcuts
Zotero.Keys.init();
@@ -1042,6 +1044,15 @@ Zotero.Prefs = new function(){
Zotero.Schema.stopRepositoryTimer();
}
break;
+
+ case "zoteroDotOrgVersionHeader":
+ if (this.get("zoteroDotOrgVersionHeader")) {
+ Zotero.VersionHeader.register();
+ }
+ else {
+ Zotero.VersionHeader.unregister();
+ }
+ break;
}
}
}
@@ -1142,6 +1153,46 @@ Zotero.Keys = new function() {
/**
+ * Add X-Zotero-Version header to HTTP requests to zotero.org
+ *
+ * @namespace
+ */
+Zotero.VersionHeader = {
+ init: function () {
+ if (Zotero.Prefs.get("zoteroDotOrgVersionHeader")) {
+ this.register();
+ }
+ },
+
+ // Called from this.init() and Zotero.Prefs.observe()
+ register: function () {
+ var observerService = Components.classes["@mozilla.org/observer-service;1"]
+ .getService(Components.interfaces.nsIObserverService);
+ observerService.addObserver(this, "http-on-modify-request", false);
+ },
+
+ observe: function (subject, topic, data) {
+ try {
+ var channel = subject.QueryInterface(Components.interfaces.nsIHttpChannel);
+ if (channel.URI.host.match(/zotero\.org$/)) {
+ channel.setRequestHeader("X-Zotero-Version", Zotero.version, false);
+ }
+ }
+ catch (e) {
+ Zotero.debug(e);
+ }
+ },
+
+ unregister: function () {
+ var observerService = Components.classes["@mozilla.org/observer-service;1"]
+ .getService(Components.interfaces.nsIObserverService);
+ observerService.removeObserver(this, "http-on-modify-request");
+ }
+}
+
+
+
+/**
* Class for creating hash arrays that behave a bit more sanely
*
* Hashes can be created in the constructor by alternating key and val:
diff --git a/defaults/preferences/zotero.js b/defaults/preferences/zotero.js
@@ -14,6 +14,7 @@ pref("extensions.zotero.debug.log",false);
pref("extensions.zotero.debug.level",5);
pref("extensions.zotero.debug.time", false);
pref("extensions.zotero.automaticScraperUpdates",true);
+pref("extensions.zotero.zoteroDotOrgVersionHeader", true);
pref("extensions.zotero.cacheTranslatorData",true);
pref("extensions.zotero.zoteroPaneOnTop",false);
pref("extensions.zotero.statusBarIcon", 2);