Skip to content
This repository has been archived by the owner on Mar 28, 2019. It is now read-only.

Commit

Permalink
Fix Next-Page value, return full URL instead of token (fixes #32)
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem committed Sep 30, 2015
1 parent a9855d0 commit 9b83369
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
13 changes: 11 additions & 2 deletions syncto/headers.py
@@ -1,14 +1,23 @@
def convert_headers(sync_raw_response, syncto_response):
from cliquet import utils


def convert_headers(sync_raw_response, current_request):
"""Convert Sync headers to Kinto compatible ones."""
response_headers = sync_raw_response.headers
syncto_response = current_request.response
headers = syncto_response.headers

last_modified = float(response_headers['X-Last-Modified'])
headers['ETag'] = '"%s"' % int(last_modified * 1000)
syncto_response.last_modified = last_modified

if 'X-Weave-Next-Offset' in response_headers:
headers['Next-Page'] = str(response_headers['X-Weave-Next-Offset'])
params = current_request.GET.copy()
params['_token'] = str(response_headers['X-Weave-Next-Offset'])
service = utils.current_service(current_request)
next_page_url = current_request.route_url(service.name, _query=params,
**current_request.matchdict)
headers['Next-Page'] = next_page_url

if 'X-Weave-Records' in response_headers:
headers['Total-Records'] = str(response_headers['X-Weave-Records'])
Expand Down
3 changes: 2 additions & 1 deletion syncto/tests/test_functional.py
Expand Up @@ -194,7 +194,8 @@ def test_collection_correctly_converts_sync_headers(self):
self.assertIn('Next-Page', resp.headers)
self.assertIn('Quota-Remaining', resp.headers)
self.assertEquals(resp.headers['Total-Records'], '1')
self.assertEquals(resp.headers['Next-Page'], '12345')
next_page = 'http://localhost/v1' + COLLECTION_URL + '?_token=12345'
self.assertEquals(resp.headers['Next-Page'], next_page)
self.assertEquals(resp.headers['Quota-Remaining'], '125')


Expand Down
2 changes: 1 addition & 1 deletion syncto/views/collection.py
Expand Up @@ -62,6 +62,6 @@ def collection_get(request):
r['last_modified'] = int(r.pop('modified') * 1000)

# Configure headers
convert_headers(sync_client.raw_resp, request.response)
convert_headers(sync_client.raw_resp, request)

return {'data': records}
4 changes: 2 additions & 2 deletions syncto/views/record.py
Expand Up @@ -41,7 +41,7 @@ def record_get(request):
record['last_modified'] = int(record.pop('modified') * 1000)

# Configure headers
convert_headers(sync_client.raw_resp, request.response)
convert_headers(sync_client.raw_resp, request)

return {'data': record}

Expand All @@ -64,7 +64,7 @@ def record_put(request):
record['id'] = record_id

# Configure headers
convert_headers(sync_client.raw_resp, request.response)
convert_headers(sync_client.raw_resp, request)

return {'data': record}

Expand Down

0 comments on commit 9b83369

Please sign in to comment.