зеркало из https://github.com/mozilla/gecko-dev.git
Handle 401s from the server correctly. (bug #509552)
This commit is contained in:
Родитель
bea7925a6b
Коммит
02a2121431
|
@ -68,6 +68,9 @@ const INITIAL_THRESHOLD = 75;
|
||||||
// threshold each time we do a sync check and don't sync that engine.
|
// threshold each time we do a sync check and don't sync that engine.
|
||||||
const THRESHOLD_DECREMENT_STEP = 25;
|
const THRESHOLD_DECREMENT_STEP = 25;
|
||||||
|
|
||||||
|
// How long before refreshing the cluster
|
||||||
|
const CLUSTER_BACKOFF = SCHEDULED_SYNC_INTERVAL;
|
||||||
|
|
||||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
Cu.import("resource://weave/ext/Sync.js");
|
Cu.import("resource://weave/ext/Sync.js");
|
||||||
Cu.import("resource://weave/log4moz.js");
|
Cu.import("resource://weave/log4moz.js");
|
||||||
|
@ -499,7 +502,19 @@ WeaveSvc.prototype = {
|
||||||
this._log.debug("Error setting cluster for user " + username);
|
this._log.debug("Error setting cluster for user " + username);
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// update cluster if required. returns false if the update was not required
|
||||||
|
updateCluster: function WeaveSvc_updateCluster(username) {
|
||||||
|
let cTime = Date.now();
|
||||||
|
let lastUp = parseFloat(Svc.Prefs.get("lastClusterUpdate"));
|
||||||
|
if (!lastUp || ((cTime - lastUp) >= CLUSTER_BACKOFF)) {
|
||||||
|
this.setCluster(username);
|
||||||
|
Svc.Prefs.set("lastClusterUpdate", cTime.toString());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
verifyLogin: function WeaveSvc_verifyLogin(username, password, passphrase, isLogin)
|
verifyLogin: function WeaveSvc_verifyLogin(username, password, passphrase, isLogin)
|
||||||
this._catch(this._notify("verify-login", "", function() {
|
this._catch(this._notify("verify-login", "", function() {
|
||||||
this._log.debug("Verifying login for user " + username);
|
this._log.debug("Verifying login for user " + username);
|
||||||
|
@ -519,7 +534,17 @@ WeaveSvc.prototype = {
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
res.get();
|
|
||||||
|
// login may fail because of cluster change
|
||||||
|
try {
|
||||||
|
res.get();
|
||||||
|
} catch (e) {
|
||||||
|
if (res.lastChannel.responseStatus == 401) {
|
||||||
|
if (this.updateCluster(username))
|
||||||
|
return this.verifyLogin(username, password, passphrase, isLogin);
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
if (passphrase)
|
if (passphrase)
|
||||||
return this.verifyPassphrase(username, password, passphrase);
|
return this.verifyPassphrase(username, password, passphrase);
|
||||||
|
@ -1083,6 +1108,11 @@ WeaveSvc.prototype = {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
|
// maybe a 401, cluster update needed?
|
||||||
|
if (e.constructor.name == "RequestException" && e.status == 401) {
|
||||||
|
if (this.updateCluster(this.username))
|
||||||
|
return this._syncEngine(engine);
|
||||||
|
}
|
||||||
this._syncError = true;
|
this._syncError = true;
|
||||||
this._weaveStatusCode = WEAVE_STATUS_PARTIAL;
|
this._weaveStatusCode = WEAVE_STATUS_PARTIAL;
|
||||||
this._detailedStatus.setEngineStatus(engine.name, e);
|
this._detailedStatus.setEngineStatus(engine.name, e);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче