Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@sugarlabs.org>2014-05-02 12:43:52 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2014-05-02 12:43:52 (GMT)
commit5f0b31906d28188ce420b84a25cac9c06787c614 (patch)
treeef813c8c60788908f12ca2aa666c0b67eaec181f
parent4596cf36203db51cd371b21fd6639b9c55166f17 (diff)
Tune API url if it permanently relocates
-rw-r--r--TODO1
-rw-r--r--sugar_network/client/routes.py14
2 files changed, 12 insertions, 3 deletions
diff --git a/TODO b/TODO
index 27f2742..b956484 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,6 @@
- auth while offline posts
- do not return Context.releases while non-slave sync
- deliver spawn events only to local subscribers
-- if node relocates api calls, do it only once in toolkit.http
- switch auth from WWW-AUTHENTICATE to mutual authentication over the HTTPS
- restrict ACL.LOCAL routes only to localhost clients
- pull node changes periodically for checked-in contexts
diff --git a/sugar_network/client/routes.py b/sugar_network/client/routes.py
index 4bdd10f..96c6fac 100644
--- a/sugar_network/client/routes.py
+++ b/sugar_network/client/routes.py
@@ -14,7 +14,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
+import json
import logging
+from urlparse import urlsplit
from httplib import IncompleteRead
from os.path import join
@@ -303,8 +305,16 @@ class ClientRoutes(FrontRoutes, JournalRoutes):
def handshake(url):
_logger.debug('Connecting to %r node', url)
self._remote = client.Connection(url, creds=self._creds)
- status = self._remote.get(cmd='status')
- seqno = status.get('seqno')
+
+ reply = self._remote.request('GET', params={'cmd': 'status'})
+ reply_url = urlsplit(reply.url)
+ reply_url = '%s://%s' % (reply_url.scheme, reply_url.netloc)
+ if reply_url != url:
+ _logger.info('Replace %r API url by %r',
+ self._remote.url, reply_url)
+ self._remote.url = reply_url
+
+ seqno = json.loads(reply.content).get('seqno')
if seqno and 'releases' in seqno:
this.injector.seqno = seqno['releases']
if self.inline():