1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-24 06:59:52 +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:
Ilya Kreymer 2014-07-30 13:06:18 -07:00
parent 527ad0d60e
commit eff5a74ec7
6 changed files with 18 additions and 16 deletions

View File

@ -55,6 +55,7 @@ class ProxyRouter(object):
PAC_PATH = '/proxy.pac' PAC_PATH = '/proxy.pac'
BLOCK_SIZE = 4096 BLOCK_SIZE = 4096
DEF_MAGIC_NAME = 'pywb.proxy'
def __init__(self, routes, **kwargs): def __init__(self, routes, **kwargs):
self.hostpaths = kwargs.get('hostpaths') self.hostpaths = kwargs.get('hostpaths')
@ -65,13 +66,16 @@ class ProxyRouter(object):
if proxy_options: if proxy_options:
proxy_options = proxy_options.get('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'): if proxy_options.get('cookie_resolver'):
self.resolver = CookieResolver(routes, proxy_options) self.resolver = CookieResolver(routes, proxy_options)
else: else:
self.resolver = ProxyAuthResolver(routes, proxy_options) 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.insert_banner = proxy_options.get('banner_only_replay', False)
self.unaltered = proxy_options.get('unaltered_replay', False) self.unaltered = proxy_options.get('unaltered_replay', False)
@ -134,10 +138,10 @@ class ProxyRouter(object):
if parts.query: if parts.query:
env['pywb.proxy_req_uri'] += '?' + parts.query env['pywb.proxy_req_uri'] += '?' + parts.query
# static # select prefix
static_prefix = 'static.' + self.magic_name 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'] env['REL_REQUEST_URI'] = env['pywb.proxy_req_uri']
return None return None
@ -147,13 +151,12 @@ class ProxyRouter(object):
if response: if response:
return 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, wbrequest = route.request_class(env,
request_uri=url, request_uri=url,
wb_url_str=url, wb_url_str=url,
coll=coll, coll=coll,
# host_prefix=self.hostpaths[0],
host_prefix=host_prefix, host_prefix=host_prefix,
wburl_class=route.handler.get_wburl_type(), wburl_class=route.handler.get_wburl_type(),
urlrewriter_class=HttpsUrlRewriter, urlrewriter_class=HttpsUrlRewriter,

View File

@ -119,7 +119,7 @@ class CookieResolver(BaseCollResolver): # pragma: no cover
def __init__(self, routes, config): def __init__(self, routes, config):
config['pre_connect'] = False config['pre_connect'] = False
super(CookieResolver, self).__init__(routes, config) 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.cookie_name = config.get('cookie_name', '__pywb_coll')
self.proxy_select_view = config.get('proxy_select_view') self.proxy_select_view = config.get('proxy_select_view')

View File

@ -135,14 +135,12 @@ class WSGIApp(object):
logging.info(err_msg) logging.info(err_msg)
err_details = None err_details = None
is_proxy_mode = env.get('pywb.proxy_host') is not None
if error_view: if error_view:
return error_view.render_response(exc_type=type(exc).__name__, return error_view.render_response(exc_type=type(exc).__name__,
err_msg=err_msg, err_msg=err_msg,
err_details=err_details, err_details=err_details,
status=status, status=status,
is_proxy_mode=is_proxy_mode, env=env,
err_url=err_url) err_url=err_url)
else: else:
return WbResponse.text_response(status + ' Error: ' + err_msg, return WbResponse.text_response(status + ' Error: ' + err_msg,

View File

@ -70,8 +70,9 @@ function init_banner() {
text += "<b id='_wb_capture_info'>" + capture_str + "</b>"; text += "<b id='_wb_capture_info'>" + capture_str + "</b>";
if (wbinfo.is_proxy_mode && wbinfo.url) { if (wbinfo.proxy_select && wbinfo.url) {
text += '<br/><a href="//select.pywb-proxy.com/' + wbinfo.url + '">Switch Collection</a>'; full_url = wbinfo.proxy_select + "/" + wbinfo.url;
text += '<br/><a href="//' + full_url + '">Switch Collection</a>';
} }
banner.innerHTML = text; banner.innerHTML = text;

View File

@ -10,9 +10,9 @@
</p> </p>
{% endif %} {% 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> <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> </p>
{% endif %} {% endif %}

View File

@ -20,7 +20,7 @@
wbinfo.is_frame_mp = {{"true" if wbrequest.wb_url.mod == 'mp_' else "false"}}; wbinfo.is_frame_mp = {{"true" if wbrequest.wb_url.mod == 'mp_' else "false"}};
wbinfo.canon_url = "{{ canon_url }}"; wbinfo.canon_url = "{{ canon_url }}";
wbinfo.is_live = {{ "true" if cdx.is_live else "false" }}; 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>
<script src='{{ wbrequest.host_prefix }}/{{ static_path }}/wb.js'> </script> <script src='{{ wbrequest.host_prefix }}/{{ static_path }}/wb.js'> </script>
<link rel='stylesheet' href='{{ wbrequest.host_prefix }}/{{ static_path }}/wb.css'/> <link rel='stylesheet' href='{{ wbrequest.host_prefix }}/{{ static_path }}/wb.css'/>