mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-24 06:59:52 +01:00
wbrequest: add options dictionary to store misc request options
This commit is contained in:
parent
fa813bdd19
commit
a2973b04e7
@ -11,15 +11,13 @@ LINK_FORMAT = 'application/link-format'
|
|||||||
#=================================================================
|
#=================================================================
|
||||||
class MementoReqMixin(object):
|
class MementoReqMixin(object):
|
||||||
def _parse_extra(self):
|
def _parse_extra(self):
|
||||||
self.is_timegate = False
|
|
||||||
|
|
||||||
if not self.wb_url:
|
if not self.wb_url:
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.wb_url.type != self.wb_url.LATEST_REPLAY:
|
if self.wb_url.type != self.wb_url.LATEST_REPLAY:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.is_timegate = True
|
self.options['is_timegate'] = True
|
||||||
|
|
||||||
accept_datetime = self.env.get('HTTP_ACCEPT_DATETIME')
|
accept_datetime = self.env.get('HTTP_ACCEPT_DATETIME')
|
||||||
if not accept_datetime:
|
if not accept_datetime:
|
||||||
@ -48,7 +46,7 @@ class MementoRespMixin(object):
|
|||||||
if not wbrequest or not wbrequest.wb_url:
|
if not wbrequest or not wbrequest.wb_url:
|
||||||
return
|
return
|
||||||
|
|
||||||
is_timegate = wbrequest.is_timegate
|
is_timegate = wbrequest.options.get('is_timegate', False)
|
||||||
|
|
||||||
if is_timegate:
|
if is_timegate:
|
||||||
self.status_headers.headers.append(('Vary', 'accept-datetime'))
|
self.status_headers.headers.append(('Vary', 'accept-datetime'))
|
||||||
@ -59,7 +57,7 @@ class MementoRespMixin(object):
|
|||||||
is_memento = False
|
is_memento = False
|
||||||
|
|
||||||
# otherwise, if in proxy mode, then always a memento
|
# otherwise, if in proxy mode, then always a memento
|
||||||
elif wbrequest.is_proxy:
|
elif wbrequest.options['is_proxy']:
|
||||||
is_memento = True
|
is_memento = True
|
||||||
|
|
||||||
# otherwise only for replay
|
# otherwise only for replay
|
||||||
@ -80,7 +78,7 @@ class MementoRespMixin(object):
|
|||||||
link.append(self.make_link(req_url, 'original'))
|
link.append(self.make_link(req_url, 'original'))
|
||||||
|
|
||||||
# for now, include timemap only in non-proxy mode
|
# for now, include timemap only in non-proxy mode
|
||||||
if not wbrequest.is_proxy and (is_memento or is_timegate):
|
if not wbrequest.options['is_proxy'] and (is_memento or is_timegate):
|
||||||
link.append(self.make_timemap_link(wbrequest))
|
link.append(self.make_timemap_link(wbrequest))
|
||||||
|
|
||||||
if is_memento and not is_timegate:
|
if is_memento and not is_timegate:
|
||||||
|
@ -78,12 +78,11 @@ class WbRequest(object):
|
|||||||
|
|
||||||
self.referrer = env.get('HTTP_REFERER')
|
self.referrer = env.get('HTTP_REFERER')
|
||||||
|
|
||||||
self.is_ajax = self._is_ajax()
|
self.options = dict()
|
||||||
|
self.options['is_ajax'] = self._is_ajax()
|
||||||
|
self.options['is_proxy'] = is_proxy
|
||||||
|
|
||||||
self.query_filter = []
|
self.query_filter = []
|
||||||
|
|
||||||
self.is_proxy = is_proxy
|
|
||||||
|
|
||||||
self.custom_params = {}
|
self.custom_params = {}
|
||||||
|
|
||||||
# PERF
|
# PERF
|
||||||
|
@ -8,8 +8,6 @@ from pywb.utils.loaders import BlockLoader
|
|||||||
from pywb.framework.basehandlers import BaseHandler, WbUrlHandler
|
from pywb.framework.basehandlers import BaseHandler, WbUrlHandler
|
||||||
from pywb.framework.wbrequestresponse import WbResponse
|
from pywb.framework.wbrequestresponse import WbResponse
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
|
|
||||||
#=================================================================
|
#=================================================================
|
||||||
# Standard WB Handler
|
# Standard WB Handler
|
||||||
|
@ -66,8 +66,9 @@ class BaseContentView(object):
|
|||||||
# render top level frame if in frame mode
|
# render top level frame if in frame mode
|
||||||
# (not supported in proxy mode)
|
# (not supported in proxy mode)
|
||||||
if (self.is_frame_mode and
|
if (self.is_frame_mode and
|
||||||
not wbrequest.is_proxy and
|
not wbrequest.wb_url.mod and
|
||||||
not wbrequest.wb_url.mod):
|
not wbrequest.options['is_proxy'] and
|
||||||
|
not wbrequest.options.get('is_timegate', False)):
|
||||||
|
|
||||||
embed_url = wbrequest.wb_url.to_str(mod=self._mp_mod)
|
embed_url = wbrequest.wb_url.to_str(mod=self._mp_mod)
|
||||||
timestamp = datetime_to_timestamp(datetime.datetime.utcnow())
|
timestamp = datetime_to_timestamp(datetime.datetime.utcnow())
|
||||||
@ -259,12 +260,10 @@ class ReplayView(BaseContentView):
|
|||||||
return content
|
return content
|
||||||
|
|
||||||
def _redirect_if_needed(self, wbrequest, cdx):
|
def _redirect_if_needed(self, wbrequest, cdx):
|
||||||
if wbrequest.is_proxy:
|
if wbrequest.options['is_proxy']:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# todo: generalize this?
|
redir_needed = (wbrequest.options.get('is_timegate', False))
|
||||||
redir_needed = (hasattr(wbrequest, 'is_timegate') and
|
|
||||||
wbrequest.is_timegate)
|
|
||||||
|
|
||||||
if not redir_needed and self.redir_to_exact:
|
if not redir_needed and self.redir_to_exact:
|
||||||
redir_needed = (cdx['timestamp'] != wbrequest.wb_url.timestamp)
|
redir_needed = (cdx['timestamp'] != wbrequest.wb_url.timestamp)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user