From c2f99d6cfdfd5b2f33f4dc150e2fb5bbb7023193 Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Sun, 19 Jul 2015 00:11:25 -0700 Subject: [PATCH] replay/memento: always include 'Content-Location' for in no-redir mode replay (not just for memento timegate), #122 --- pywb/framework/memento.py | 8 ++++---- pywb/webapp/replay_views.py | 10 ++++++++++ tests/test_integration.py | 16 ++++++++-------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/pywb/framework/memento.py b/pywb/framework/memento.py index eff48152..079b3d1e 100644 --- a/pywb/framework/memento.py +++ b/pywb/framework/memento.py @@ -106,10 +106,10 @@ class MementoRespMixin(object): timestamp=ts, url=url) - # Must set content location - if is_memento and is_timegate: - self.status_headers.headers.append(('Content-Location', - canon_link)) + # set in replay_views -- Must set content location + #if is_memento and is_timegate: + # self.status_headers.headers.append(('Content-Location', + # canon_link)) # don't set memento link for very long urls... if len(canon_link) < 512: diff --git a/pywb/webapp/replay_views.py b/pywb/webapp/replay_views.py index 832cf66c..ea84d85b 100644 --- a/pywb/webapp/replay_views.py +++ b/pywb/webapp/replay_views.py @@ -191,6 +191,16 @@ class ReplayView(object): response_iter, self.buffer_max_size) + # Set Content-Location if not exact capture + if not self.redir_to_exact: + mod = wbrequest.options.get('replay_mod', wbrequest.wb_url.mod) + canon_url = (wbrequest.urlrewriter. + get_new_url(timestamp=cdx['timestamp'], + url=cdx['url'], + mod=mod)) + + status_headers.headers.append(('Content-Location', canon_url)) + response = self.response_class(status_headers, response_iter, wbrequest=wbrequest, diff --git a/tests/test_integration.py b/tests/test_integration.py index c2533da0..a6e06e29 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -303,23 +303,23 @@ class TestWb: def test_redirect_non_exact_latest_replay_ts(self): resp = self.testapp.get('/pywb-non-exact/http://example.com/') - assert resp.status_int == 302 + assert resp.status_int == 200 - assert resp.headers['Location'].endswith('/http://example.com') + assert resp.headers['Content-Location'].endswith('/http://example.com') # extract ts, which should be current time - ts = resp.headers['Location'].rsplit('/http://')[0].rsplit('/', 1)[-1] - assert len(ts) == 14, ts - resp = resp.follow() + ts = resp.headers['Content-Location'].rsplit('/http://')[0].rsplit('/', 1)[-1] + assert ts == '20140127171251' + #resp = resp.follow() - self._assert_basic_html(resp) + #self._assert_basic_html(resp) # ensure the current ts is present in the links assert '"{0}"'.format(ts) in resp.body - assert '/pywb-non-exact/{0}/http://www.iana.org/domains/example'.format(ts) in resp.body + assert '/pywb-non-exact/http://www.iana.org/domains/example' in resp.body # ensure ts is current ts - assert timestamp_now() >= ts, ts + #assert timestamp_now() >= ts, ts def test_redirect_relative_3(self): # webtest uses Host: localhost:80 by default