mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-24 06:59:52 +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:
parent
a25096968a
commit
1e54f8c8fa
@ -200,10 +200,13 @@ class ProxyRouter(object):
|
|||||||
host_prefix = custom_prefix
|
host_prefix = custom_prefix
|
||||||
urlrewriter_class = UrlRewriter
|
urlrewriter_class = UrlRewriter
|
||||||
abs_prefix = True
|
abs_prefix = True
|
||||||
|
# always rewrite to absolute here
|
||||||
|
rewrite_opts = dict(no_match_rel=True)
|
||||||
else:
|
else:
|
||||||
host_prefix = env['pywb.proxy_scheme'] + '://' + self.magic_name
|
host_prefix = env['pywb.proxy_scheme'] + '://' + self.magic_name
|
||||||
urlrewriter_class = SchemeOnlyUrlRewriter
|
urlrewriter_class = SchemeOnlyUrlRewriter
|
||||||
abs_prefix = False
|
abs_prefix = False
|
||||||
|
rewrite_opts = {}
|
||||||
|
|
||||||
# special case for proxy calendar
|
# special case for proxy calendar
|
||||||
if (env['pywb.proxy_host'] == 'query.' + self.magic_name):
|
if (env['pywb.proxy_host'] == 'query.' + self.magic_name):
|
||||||
@ -222,6 +225,7 @@ class ProxyRouter(object):
|
|||||||
wburl_class=route.handler.get_wburl_type(),
|
wburl_class=route.handler.get_wburl_type(),
|
||||||
urlrewriter_class=urlrewriter_class,
|
urlrewriter_class=urlrewriter_class,
|
||||||
use_abs_prefix=abs_prefix,
|
use_abs_prefix=abs_prefix,
|
||||||
|
rewrite_opts=rewrite_opts,
|
||||||
is_proxy=True)
|
is_proxy=True)
|
||||||
|
|
||||||
if matcher:
|
if matcher:
|
||||||
|
@ -13,12 +13,12 @@ from server_mock import make_setup_module, BaseIntegration
|
|||||||
setup_module = make_setup_module('tests/test_config_proxy_no_banner.yaml')
|
setup_module = make_setup_module('tests/test_config_proxy_no_banner.yaml')
|
||||||
|
|
||||||
class TestProxyNoBanner(BaseIntegration):
|
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)
|
parts = urlsplit(uri)
|
||||||
env = dict(REQUEST_URI=uri, QUERY_STRING=parts.query, SCRIPT_NAME='',
|
env = dict(REQUEST_URI=uri, QUERY_STRING=parts.query, SCRIPT_NAME='',
|
||||||
SERVER_PROTOCOL=server_protocol, REMOTE_ADDR=addr)
|
SERVER_PROTOCOL=server_protocol, REMOTE_ADDR=addr)
|
||||||
# 'Simulating' proxy by settings REQUEST_URI explicitly to full url with empty SCRIPT_NAME
|
# '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):
|
def test_proxy_chunked(self):
|
||||||
resp = self.get_url('http://www.iana.org/_img/2013.1/icann-logo.svg', server_protocol='HTTP/1.1')
|
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')
|
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 resp.headers['Transfer-Encoding'] == 'chunked'
|
||||||
assert int(resp.headers['Content-Length']) == len(resp.body)
|
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')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user