From eff5a74ec76441742603452696585680b6324378 Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Wed, 30 Jul 2014 13:06:18 -0700 Subject: [PATCH] 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 --- pywb/framework/proxy.py | 17 ++++++++++------- pywb/framework/proxy_resolvers.py | 2 +- pywb/framework/wsgi_wrappers.py | 4 +--- pywb/static/wb.js | 5 +++-- pywb/ui/error.html | 4 ++-- pywb/ui/head_insert.html | 2 +- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/pywb/framework/proxy.py b/pywb/framework/proxy.py index 315594c9..ba6d3266 100644 --- a/pywb/framework/proxy.py +++ b/pywb/framework/proxy.py @@ -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, diff --git a/pywb/framework/proxy_resolvers.py b/pywb/framework/proxy_resolvers.py index 1b33be01..9062bafd 100644 --- a/pywb/framework/proxy_resolvers.py +++ b/pywb/framework/proxy_resolvers.py @@ -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') diff --git a/pywb/framework/wsgi_wrappers.py b/pywb/framework/wsgi_wrappers.py index 85e23aaa..d1a4f772 100644 --- a/pywb/framework/wsgi_wrappers.py +++ b/pywb/framework/wsgi_wrappers.py @@ -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, diff --git a/pywb/static/wb.js b/pywb/static/wb.js index 4a23b03c..fb2c3ac3 100644 --- a/pywb/static/wb.js +++ b/pywb/static/wb.js @@ -70,8 +70,9 @@ function init_banner() { text += "" + capture_str + ""; - if (wbinfo.is_proxy_mode && wbinfo.url) { - text += '
Switch Collection'; + if (wbinfo.proxy_select && wbinfo.url) { + full_url = wbinfo.proxy_select + "/" + wbinfo.url; + text += '
Switch Collection'; } banner.innerHTML = text; diff --git a/pywb/ui/error.html b/pywb/ui/error.html index d7231893..6453e987 100644 --- a/pywb/ui/error.html +++ b/pywb/ui/error.html @@ -10,9 +10,9 @@

{% 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' %}

-Try Different Collections +Try Different Collections

{% endif %} diff --git a/pywb/ui/head_insert.html b/pywb/ui/head_insert.html index d9e1207b..98330da9 100644 --- a/pywb/ui/head_insert.html +++ b/pywb/ui/head_insert.html @@ -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 }}";