1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00

proxy: add tests for proxy-mode 'Pywb-Rewrite-Prefix' header which adds optional prefix to proxy mode rewrites.. ensures such rewrites always absolute to include the prefix

This commit is contained in:
Ilya Kreymer 2015-12-29 16:10:23 -08:00
parent a25096968a
commit 1e54f8c8fa
2 changed files with 18 additions and 2 deletions

View File

@ -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:

View File

@ -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')