Add X-Zotero-Version header to HTTP requests to zotero.org
This commit is contained in:
parent
bf8e4eae28
commit
340f54c8b0
3 changed files with 57 additions and 0 deletions
|
@ -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"/>
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue