mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 08:04:49 +01:00
proxy: path fixup, using default magic name of 'pywb.proxy', default
selector 'select.pywb.proxy' stored in env['pywb_select'] and accessible to head insert and error handler
This commit is contained in:
parent
527ad0d60e
commit
eff5a74ec7
@ -55,6 +55,7 @@ class ProxyRouter(object):
|
||||
|
||||
PAC_PATH = '/proxy.pac'
|
||||
BLOCK_SIZE = 4096
|
||||
DEF_MAGIC_NAME = 'pywb.proxy'
|
||||
|
||||
def __init__(self, routes, **kwargs):
|
||||
self.hostpaths = kwargs.get('hostpaths')
|
||||
@ -65,13 +66,16 @@ class ProxyRouter(object):
|
||||
if proxy_options:
|
||||
proxy_options = proxy_options.get('proxy_options', {})
|
||||
|
||||
self.magic_name = proxy_options.get('magic_name')
|
||||
if not self.magic_name:
|
||||
self.magic_name = self.DEF_MAGIC_NAME
|
||||
proxy_options['magic_name'] = self.magic_name
|
||||
|
||||
if proxy_options.get('cookie_resolver'):
|
||||
self.resolver = CookieResolver(routes, proxy_options)
|
||||
else:
|
||||
self.resolver = ProxyAuthResolver(routes, proxy_options)
|
||||
|
||||
self.magic_name = proxy_options.get('magic_name', 'pywb-proxy.com')
|
||||
|
||||
self.insert_banner = proxy_options.get('banner_only_replay', False)
|
||||
self.unaltered = proxy_options.get('unaltered_replay', False)
|
||||
|
||||
@ -134,10 +138,10 @@ class ProxyRouter(object):
|
||||
if parts.query:
|
||||
env['pywb.proxy_req_uri'] += '?' + parts.query
|
||||
|
||||
# static
|
||||
static_prefix = 'static.' + self.magic_name
|
||||
# select prefix
|
||||
env['pywb_proxy_select'] = 'select.' + self.magic_name
|
||||
|
||||
if env['pywb.proxy_host'] == static_prefix:
|
||||
if env['pywb.proxy_host'] == self.magic_name:
|
||||
env['REL_REQUEST_URI'] = env['pywb.proxy_req_uri']
|
||||
return None
|
||||
|
||||
@ -147,13 +151,12 @@ class ProxyRouter(object):
|
||||
if response:
|
||||
return response
|
||||
|
||||
host_prefix = env['pywb.proxy_scheme'] + '://' + static_prefix
|
||||
host_prefix = env['pywb.proxy_scheme'] + '://' + self.magic_name
|
||||
|
||||
wbrequest = route.request_class(env,
|
||||
request_uri=url,
|
||||
wb_url_str=url,
|
||||
coll=coll,
|
||||
# host_prefix=self.hostpaths[0],
|
||||
host_prefix=host_prefix,
|
||||
wburl_class=route.handler.get_wburl_type(),
|
||||
urlrewriter_class=HttpsUrlRewriter,
|
||||
|
@ -119,7 +119,7 @@ class CookieResolver(BaseCollResolver): # pragma: no cover
|
||||
def __init__(self, routes, config):
|
||||
config['pre_connect'] = False
|
||||
super(CookieResolver, self).__init__(routes, config)
|
||||
self.magic_name = config.get('magic_name', 'pywb-proxy.com')
|
||||
self.magic_name = config['magic_name']
|
||||
self.cookie_name = config.get('cookie_name', '__pywb_coll')
|
||||
self.proxy_select_view = config.get('proxy_select_view')
|
||||
|
||||
|
@ -135,14 +135,12 @@ class WSGIApp(object):
|
||||
logging.info(err_msg)
|
||||
err_details = None
|
||||
|
||||
is_proxy_mode = env.get('pywb.proxy_host') is not None
|
||||
|
||||
if error_view:
|
||||
return error_view.render_response(exc_type=type(exc).__name__,
|
||||
err_msg=err_msg,
|
||||
err_details=err_details,
|
||||
status=status,
|
||||
is_proxy_mode=is_proxy_mode,
|
||||
env=env,
|
||||
err_url=err_url)
|
||||
else:
|
||||
return WbResponse.text_response(status + ' Error: ' + err_msg,
|
||||
|
@ -70,8 +70,9 @@ function init_banner() {
|
||||
|
||||
text += "<b id='_wb_capture_info'>" + capture_str + "</b>";
|
||||
|
||||
if (wbinfo.is_proxy_mode && wbinfo.url) {
|
||||
text += '<br/><a href="//select.pywb-proxy.com/' + wbinfo.url + '">Switch Collection</a>';
|
||||
if (wbinfo.proxy_select && wbinfo.url) {
|
||||
full_url = wbinfo.proxy_select + "/" + wbinfo.url;
|
||||
text += '<br/><a href="//' + full_url + '">Switch Collection</a>';
|
||||
}
|
||||
|
||||
banner.innerHTML = text;
|
||||
|
@ -10,9 +10,9 @@
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% if is_proxy_mode and err_url and status == '404 Not Found' %}
|
||||
{% if env.pywb_proxy_select and err_url and status == '404 Not Found' %}
|
||||
<p>
|
||||
<a href="//select.pywb-proxy.com/{{ err_url }}">Try Different Collections</a>
|
||||
<a href="//{{ env.pywb_proxy_select }}/{{ err_url }}">Try Different Collections</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
wbinfo.is_frame_mp = {{"true" if wbrequest.wb_url.mod == 'mp_' else "false"}};
|
||||
wbinfo.canon_url = "{{ canon_url }}";
|
||||
wbinfo.is_live = {{ "true" if cdx.is_live else "false" }};
|
||||
wbinfo.is_proxy_mode = {{ "true" if wbrequest.options.is_proxy else "false" }};
|
||||
wbinfo.proxy_select = "{{ wbrequest.env.pywb_proxy_select }}";
|
||||
</script>
|
||||
<script src='{{ wbrequest.host_prefix }}/{{ static_path }}/wb.js'> </script>
|
||||
<link rel='stylesheet' href='{{ wbrequest.host_prefix }}/{{ static_path }}/wb.css'/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user