diff --git a/chrome/content/zotero/preferences/preferences.xul b/chrome/content/zotero/preferences/preferences.xul
index 0db310ca7d..97ec19bf46 100644
--- a/chrome/content/zotero/preferences/preferences.xul
+++ b/chrome/content/zotero/preferences/preferences.xul
@@ -49,6 +49,7 @@ To add a new preference:
+
@@ -118,6 +119,10 @@ To add a new preference:
+
+
diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js
index 42134eec0d..33a4553e9e 100644
--- 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;
}
}
}
@@ -1141,6 +1152,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
*
diff --git a/defaults/preferences/zotero.js b/defaults/preferences/zotero.js
index ec66dbf87a..55d2daeebe 100644
--- 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);