Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar_network
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 /sugar_network
parent4596cf36203db51cd371b21fd6639b9c55166f17 (diff)
Tune API url if it permanently relocates
Diffstat (limited to 'sugar_network')
-rw-r--r--sugar_network/client/routes.py14
1 files changed, 12 insertions, 2 deletions
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():