mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
memento: add rel="memento" header to timegate as well, improve memento test, clearly differntiate between
timegate redirect and intermediate resource redirect, related to #70
This commit is contained in:
parent
c4d5dd4690
commit
9623f95439
@ -29,6 +29,7 @@ class MementoReqMixin(object):
|
||||
raise BadRequestException('Invalid Accept-Datetime: ' +
|
||||
accept_datetime)
|
||||
|
||||
# note: this changes from LATEST_REPLAY -> REPLAY
|
||||
self.wb_url.set_replay_timestamp(timestamp)
|
||||
|
||||
|
||||
@ -68,26 +69,29 @@ class MementoRespMixin(object):
|
||||
elif wbrequest.options['is_proxy']:
|
||||
is_memento = True
|
||||
|
||||
# otherwise only for replay
|
||||
else:
|
||||
# otherwise only if timestamp replay (and not a timegate)
|
||||
elif not is_timegate:
|
||||
is_memento = (wbrequest.wb_url.type == wbrequest.wb_url.REPLAY)
|
||||
|
||||
link = []
|
||||
|
||||
if is_memento:
|
||||
if is_memento or is_timegate:
|
||||
if cdx:
|
||||
http_date = timestamp_to_http_date(cdx['timestamp'])
|
||||
ts = cdx['timestamp']
|
||||
# for top frame
|
||||
elif wbrequest.wb_url.timestamp:
|
||||
http_date = timestamp_to_http_date(wbrequest.wb_url.timestamp)
|
||||
ts = wbrequest.wb_url.timestamp
|
||||
else:
|
||||
http_date = None
|
||||
ts = None
|
||||
|
||||
if http_date:
|
||||
self.status_headers.headers.append(('Memento-Datetime',
|
||||
http_date))
|
||||
if ts:
|
||||
http_date = timestamp_to_http_date(ts)
|
||||
|
||||
canon_link = wbrequest.urlrewriter.get_new_url(mod='')
|
||||
if is_memento:
|
||||
self.status_headers.headers.append(('Memento-Datetime',
|
||||
http_date))
|
||||
|
||||
canon_link = wbrequest.urlrewriter.get_new_url(mod='', timestamp=ts)
|
||||
link.append(self.make_memento_link(canon_link,
|
||||
'memento',
|
||||
http_date))
|
||||
|
@ -219,7 +219,8 @@ class ReplayView(object):
|
||||
if wbrequest.custom_params.get('noredir'):
|
||||
return None
|
||||
|
||||
redir_needed = (wbrequest.options.get('is_timegate', False))
|
||||
is_memento_timegate = (wbrequest.options.get('is_timegate', False))
|
||||
redir_needed = is_memento_timegate
|
||||
|
||||
if not redir_needed and self.redir_to_exact:
|
||||
redir_needed = (cdx['timestamp'] != wbrequest.wb_url.timestamp)
|
||||
@ -238,15 +239,19 @@ class ReplayView(object):
|
||||
# FF shows a confirm dialog, so can't use 307 effectively
|
||||
# was: statusline = '307 Same-Method Internal Redirect'
|
||||
return None
|
||||
elif is_memento_timegate:
|
||||
statusline = '302 Found'
|
||||
else:
|
||||
# clear cdx line to indicate internal redirect
|
||||
statusline = '302 Internal Redirect'
|
||||
cdx = None
|
||||
|
||||
status_headers = StatusAndHeaders(statusline,
|
||||
[('Location', new_url)])
|
||||
|
||||
# don't include cdx to indicate internal redirect
|
||||
return self.response_class(status_headers,
|
||||
wbrequest=wbrequest)
|
||||
wbrequest=wbrequest,
|
||||
cdx=cdx)
|
||||
|
||||
def _reject_self_redirect(self, wbrequest, cdx, status_headers):
|
||||
"""
|
||||
|
@ -39,6 +39,8 @@ class TestWb:
|
||||
"""
|
||||
TimeGate with no Accept-Datetime header
|
||||
"""
|
||||
|
||||
dt = 'Mon, 27 Jan 2014 17:12:39 GMT'
|
||||
resp = self.testapp.get('/pywb/http://www.iana.org/_css/2013.1/screen.css')
|
||||
|
||||
assert resp.status_int == 302
|
||||
@ -48,6 +50,7 @@ class TestWb:
|
||||
links = self.get_links(resp)
|
||||
assert '<http://www.iana.org/_css/2013.1/screen.css>; rel="original"' in links
|
||||
assert self.make_timemap_link('http://www.iana.org/_css/2013.1/screen.css') in links
|
||||
assert self.make_memento_link('http://www.iana.org/_css/2013.1/screen.css', '20140127171239', dt) in links
|
||||
|
||||
assert MEMENTO_DATETIME not in resp.headers
|
||||
|
||||
@ -56,9 +59,10 @@ class TestWb:
|
||||
|
||||
def test_timegate_accept_datetime(self):
|
||||
"""
|
||||
TimeGate with Accept-Datetime header
|
||||
TimeGate with Accept-Datetime header, matching exactly
|
||||
"""
|
||||
headers = {ACCEPT_DATETIME: 'Sun, 26 Jan 2014 20:08:04'}
|
||||
dt = 'Sun, 26 Jan 2014 20:08:04 GMT'
|
||||
headers = {ACCEPT_DATETIME: dt}
|
||||
resp = self.testapp.get('/pywb//http://www.iana.org/_css/2013.1/screen.css', headers=headers)
|
||||
|
||||
assert resp.status_int == 302
|
||||
@ -68,7 +72,7 @@ class TestWb:
|
||||
links = self.get_links(resp)
|
||||
assert '<http://www.iana.org/_css/2013.1/screen.css>; rel="original"' in links
|
||||
assert self.make_timemap_link('http://www.iana.org/_css/2013.1/screen.css') in links
|
||||
|
||||
assert self.make_memento_link('http://www.iana.org/_css/2013.1/screen.css', '20140126200804', dt) == links[0], links[0]
|
||||
|
||||
assert MEMENTO_DATETIME not in resp.headers
|
||||
|
||||
@ -79,7 +83,7 @@ class TestWb:
|
||||
"""
|
||||
Not a timegate, but an 'intermediate resource', redirect to closest timestamp
|
||||
"""
|
||||
headers = {ACCEPT_DATETIME: 'Sun, 26 Jan 2014 20:08:04'}
|
||||
headers = {ACCEPT_DATETIME: 'Sun, 26 Jan 2014 20:08:04 GMT'}
|
||||
# not a timegate, partial timestamp /2014/ present
|
||||
resp = self.testapp.get('/pywb/2014/http://www.iana.org/_css/2013.1/screen.css', headers=headers)
|
||||
|
||||
@ -286,7 +290,7 @@ rel="memento"; datetime="Fri, 03 Jan 2014 03:03:41 GMT"'
|
||||
# simulate proxy mode by setting REQUEST_URI
|
||||
request_uri = 'http://www.iana.org/_css/2013.1/screen.css'
|
||||
extra = dict(REQUEST_URI=request_uri, SCRIPT_NAME='')
|
||||
headers = {ACCEPT_DATETIME: 'Sun, 26 Jan 2014 20:08:04'}
|
||||
headers = {ACCEPT_DATETIME: 'Sun, 26 Jan 2014 20:08:04 GMT'}
|
||||
|
||||
resp = self.testapp.get('/x-ignore-this-x', extra_environ=extra, headers=headers)
|
||||
|
||||
@ -330,7 +334,7 @@ rel="memento"; datetime="Fri, 03 Jan 2014 03:03:41 GMT"'
|
||||
"""
|
||||
Non WbUrl memento path -- just ignore ACCEPT_DATETIME
|
||||
"""
|
||||
headers = {ACCEPT_DATETIME: 'Sun, 26 Jan 2014 20:08:04'}
|
||||
headers = {ACCEPT_DATETIME: 'Sun, 26 Jan 2014 20:08:04 GMT'}
|
||||
resp = self.testapp.get('/pywb/', headers=headers)
|
||||
assert resp.status_int == 200
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user