mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
rewrite: better parametrize live rewrite timestamp cookie, restore LiveResourceException
This commit is contained in:
parent
ef8d910d01
commit
4a39a4ed55
@ -1,5 +1,8 @@
|
||||
var update_wb_url = push_state;
|
||||
|
||||
var LIVE_COOKIE_REGEX = /pywb.timestamp=([\d]{1,14})/;
|
||||
|
||||
|
||||
function make_outer_url(url, ts)
|
||||
{
|
||||
if (ts) {
|
||||
@ -88,8 +91,7 @@ window.onpopstate = function(event) {
|
||||
}
|
||||
|
||||
function extract_ts_cookie(value) {
|
||||
var regex = /pywb.timestamp=([\d]{1,14})/;
|
||||
var result = value.match(regex);
|
||||
var result = value.match(LIVE_COOKIE_REGEX);
|
||||
if (result) {
|
||||
return result[1];
|
||||
} else {
|
||||
@ -114,10 +116,11 @@ function iframe_loaded(event) {
|
||||
ts = iframe.wbinfo.timestamp;
|
||||
is_live = iframe.wbinfo.is_live;
|
||||
} else {
|
||||
ts = extract_ts(iframe.location.href);
|
||||
if (!ts) {
|
||||
ts = extract_ts_cookie(iframe.document.cookie);
|
||||
if (ts) {
|
||||
is_live = true;
|
||||
ts = extract_ts_cookie(iframe.document.cookie);
|
||||
} else {
|
||||
ts = extract_ts(iframe.location.href);
|
||||
}
|
||||
}
|
||||
capture_str = _wb_js.ts_to_date(ts, true);
|
||||
|
@ -19,6 +19,9 @@ class LiveResourceException(WbException):
|
||||
|
||||
#=================================================================
|
||||
class RewriteHandler(SearchPageWbUrlHandler):
|
||||
|
||||
LIVE_COOKIE = 'pywb.timestamp={0}; max-age=60';
|
||||
|
||||
def __init__(self, config):
|
||||
super(RewriteHandler, self).__init__(config)
|
||||
|
||||
@ -28,6 +31,8 @@ class RewriteHandler(SearchPageWbUrlHandler):
|
||||
|
||||
self.head_insert_view = HeadInsertView.init_from_config(config)
|
||||
|
||||
self.live_cookie = config.get('live-cookie', self.LIVE_COOKIE)
|
||||
|
||||
def handle_request(self, wbrequest):
|
||||
try:
|
||||
return self.render_content(wbrequest)
|
||||
@ -35,8 +40,7 @@ class RewriteHandler(SearchPageWbUrlHandler):
|
||||
except Exception as exc:
|
||||
url = wbrequest.wb_url.url
|
||||
msg = 'Could not load the url from the live web: ' + url
|
||||
#raise LiveResourceException(msg=msg, url=url)
|
||||
raise
|
||||
raise LiveResourceException(msg=msg, url=url)
|
||||
|
||||
def _live_request_headers(self, wbrequest):
|
||||
return {}
|
||||
@ -58,9 +62,13 @@ class RewriteHandler(SearchPageWbUrlHandler):
|
||||
return self._make_response(wbrequest, *result)
|
||||
|
||||
def _make_response(self, wbrequest, status_headers, gen, is_rewritten):
|
||||
cdx = wbrequest.env['pywb.cdx']
|
||||
cookie = 'pywb.timestamp=' + cdx['timestamp'] + '; max-age=60'
|
||||
status_headers.headers.append(('Set-Cookie', cookie))
|
||||
# if cookie set, pass recorded timestamp info via cookie
|
||||
# so that client side may be able to access it
|
||||
# used by framed mode to update frame banner
|
||||
if self.live_cookie:
|
||||
cdx = wbrequest.env['pywb.cdx']
|
||||
value = self.live_cookie.format(cdx['timestamp'])
|
||||
status_headers.headers.append(('Set-Cookie', value))
|
||||
|
||||
return WbResponse(status_headers, gen)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user