commit 4dcaf2907f183eec04a3be44a8bff638c35089a4
parent 4067a1b820ddab29a1cf0368258f9d666dfca5c8
Author: Simon Kornblith <simon@simonster.com>
Date: Tue, 19 Jul 2011 21:57:32 +0000
API version checking
Diffstat:
3 files changed, 30 insertions(+), 8 deletions(-)
diff --git a/chrome/content/zotero/xpcom/connector/connector.js b/chrome/content/zotero/xpcom/connector/connector.js
@@ -25,7 +25,7 @@
Zotero.Connector = new function() {
const CONNECTOR_URI = "http://127.0.0.1:23119/";
- const CONNECTOR_SERVER_API_VERSION = 1;
+ const CONNECTOR_API_VERSION = 2;
this.isOnline = null;
@@ -69,8 +69,18 @@ Zotero.Connector = new function() {
}
if(Zotero.Connector.EXCEPTION_CODES.indexOf(req.status) !== -1) {
- Zotero.debug("Connector: Method "+method+" failed");
+ Zotero.debug("Connector: Method "+method+" failed with status "+req.status);
if(callback) callback(false, req.status);
+
+ // Check for incompatible version
+ if(req.status === 404 || req.status === 412) {
+ if(Zotero.Connector_Browser && Zotero.Connector_Browser.onIncompatibleStandaloneVersion) {
+ var standaloneVersion = req.getResponseHeader("X-Zotero-Version");
+ Zotero.Connector_Browser.onIncompatibleStandaloneVersion(Zotero.version, standaloneVersion);
+ throw "Connector: Version mismatch: Connector version "+Zotero.version
+ +", Standalone version "+(standaloneVersion ? standaloneVersion : "<unknown>");
+ }
+ }
} else {
Zotero.debug("Connector: Method "+method+" succeeded");
var val = null;
@@ -91,6 +101,10 @@ Zotero.Connector = new function() {
var uri = CONNECTOR_URI+"connector/"+method;
Zotero.HTTP.doPost(uri, JSON.stringify(data),
- newCallback, {"Content-Type":"application/json"});
+ newCallback, {
+ "Content-Type":"application/json",
+ "X-Zotero-Version":Zotero.version,
+ "X-Zotero-Connector-API-Version":CONNECTOR_API_VERSION
+ });
}
}
\ No newline at end of file
diff --git a/chrome/content/zotero/xpcom/server.js b/chrome/content/zotero/xpcom/server.js
@@ -67,6 +67,10 @@ Zotero.Server = new function() {
*/
this.generateResponse = function (status, contentType, body) {
var response = "HTTP/1.0 "+status+" "+responseCodes[status]+"\r\n";
+ if(!Zotero.isServer) {
+ response += "X-Zotero-Version: "+Zotero.version+"\r\n";
+ response += "X-Zotero-Connector-API-Version: "+CONNECTOR_API_VERSION+"\r\n";
+ }
if(body) {
if(contentType) {
diff --git a/chrome/content/zotero/xpcom/server_connector.js b/chrome/content/zotero/xpcom/server_connector.js
@@ -1,7 +1,7 @@
/*
***** BEGIN LICENSE BLOCK *****
- Copyright © 2009 Center for History and New Media
+ Copyright © 2011 Center for History and New Media
George Mason University, Fairfax, Virginia, USA
http://zotero.org
@@ -22,8 +22,7 @@
***** END LICENSE BLOCK *****
*/
-
-const CONNECTOR_SERVER_API_VERSION = 2;
+const CONNECTOR_API_VERSION = 2;
Zotero.Server.Connector = function() {};
Zotero.Server.Connector._waitingForSelection = {};
@@ -406,4 +405,9 @@ Zotero.Server.Connector.Ping.prototype = {
"init":function(postData, sendResponseCallback) {
sendResponseCallback(200);
}
-}
-\ No newline at end of file
+}
+
+
+// XXX For compatibility with older connectors; to be removed
+Zotero.Server.Endpoints["/translate/list"] = Zotero.Server.Connector.GetTranslators;
+Zotero.Server.Endpoints["/translate/save"] = Zotero.Server.Connector.SavePage;
+\ No newline at end of file