diff --git a/pywb/framework/proxy.py b/pywb/framework/proxy.py index 1a5e88ca..e2c96012 100644 --- a/pywb/framework/proxy.py +++ b/pywb/framework/proxy.py @@ -200,10 +200,13 @@ class ProxyRouter(object): host_prefix = custom_prefix urlrewriter_class = UrlRewriter abs_prefix = True + # always rewrite to absolute here + rewrite_opts = dict(no_match_rel=True) else: host_prefix = env['pywb.proxy_scheme'] + '://' + self.magic_name urlrewriter_class = SchemeOnlyUrlRewriter abs_prefix = False + rewrite_opts = {} # special case for proxy calendar if (env['pywb.proxy_host'] == 'query.' + self.magic_name): @@ -222,6 +225,7 @@ class ProxyRouter(object): wburl_class=route.handler.get_wburl_type(), urlrewriter_class=urlrewriter_class, use_abs_prefix=abs_prefix, + rewrite_opts=rewrite_opts, is_proxy=True) if matcher: diff --git a/tests/test_proxy_http_no_banner.py b/tests/test_proxy_http_no_banner.py index 3168b67e..23a6fa41 100644 --- a/tests/test_proxy_http_no_banner.py +++ b/tests/test_proxy_http_no_banner.py @@ -13,12 +13,12 @@ from server_mock import make_setup_module, BaseIntegration setup_module = make_setup_module('tests/test_config_proxy_no_banner.yaml') class TestProxyNoBanner(BaseIntegration): - def get_url(self, uri, addr='127.0.0.1', server_protocol='HTTP/1.0'): + def get_url(self, uri, addr='127.0.0.1', server_protocol='HTTP/1.0', headers={}): parts = urlsplit(uri) env = dict(REQUEST_URI=uri, QUERY_STRING=parts.query, SCRIPT_NAME='', SERVER_PROTOCOL=server_protocol, REMOTE_ADDR=addr) # 'Simulating' proxy by settings REQUEST_URI explicitly to full url with empty SCRIPT_NAME - return self.testapp.get('/x-ignore-this-x', extra_environ=env) + return self.testapp.get('/x-ignore-this-x', extra_environ=env, headers=headers) def test_proxy_chunked(self): resp = self.get_url('http://www.iana.org/_img/2013.1/icann-logo.svg', server_protocol='HTTP/1.1') @@ -46,3 +46,15 @@ class TestProxyNoBanner(BaseIntegration): resp = self.get_url('http://www.iana.org/_js/2013.1/iana.js', server_protocol='HTTP/1.1') assert resp.headers['Transfer-Encoding'] == 'chunked' assert int(resp.headers['Content-Length']) == len(resp.body) + + def test_proxy_html_no_banner(self): + resp = self.get_url('http://www.iana.org/') + + assert 'wombat' not in resp.body + assert 'href="/protocols"' in resp.body, resp.body.decode('utf-8') + + def test_proxy_html_no_banner_with_prefix(self): + resp = self.get_url('http://www.iana.org/', headers={'Pywb-Rewrite-Prefix': 'http://somehost/'}) + + assert 'wombat' not in resp.body + assert 'href="http://somehost/mp_/http://www.iana.org/protocols"' in resp.body, resp.body.decode('utf-8')