mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
More consistent env var setting / static path fix (#688)
* template/custom env var fix: - ensure pywb.host_prefix, pywb.app_prefix and pywb.static_prefix set for all requests via prepare_env() - ensure X-Forwarded-Proto is accounted for in pywb.host_prefix - call prepare_env() in handle_request(), and also in rewriterapp (in case using a different front-end app). * update wombat to 3.3.6 (includes partial fix for #684) * bump version to 2.6.3
This commit is contained in:
parent
5c35a43dac
commit
c97a66703b
@ -641,8 +641,8 @@ class FrontEndApp(object):
|
||||
urls = self.url_map.bind_to_environ(environ)
|
||||
try:
|
||||
endpoint, args = urls.match()
|
||||
# store original script_name (original prefix) before modifications are made
|
||||
environ['pywb.app_prefix'] = environ.get('SCRIPT_NAME', '')
|
||||
|
||||
self.rewriterapp.prepare_env(environ)
|
||||
|
||||
# store original script_name (original prefix) before modifications are made
|
||||
environ['ORIG_SCRIPT_NAME'] = environ.get('SCRIPT_NAME')
|
||||
|
@ -303,15 +303,24 @@ class RewriterApp(object):
|
||||
|
||||
return resp
|
||||
|
||||
def render_content(self, wb_url, kwargs, environ):
|
||||
wb_url = wb_url.replace('#', '%23')
|
||||
wb_url = WbUrl(wb_url)
|
||||
def prepare_env(self, environ):
|
||||
""" setup environ path prefixes and scheme """
|
||||
if 'pywb.host_prefix' in environ:
|
||||
return
|
||||
|
||||
proto = environ.get('HTTP_X_FORWARDED_PROTO', self.force_scheme)
|
||||
|
||||
if proto:
|
||||
environ['wsgi.url_scheme'] = proto
|
||||
|
||||
environ['pywb.host_prefix'] = self.get_host_prefix(environ)
|
||||
environ['pywb.app_prefix'] = environ.get('SCRIPT_NAME', '')
|
||||
environ['pywb.static_prefix'] = environ['pywb.host_prefix'] + environ['pywb.app_prefix'] + '/' + self.static_prefix
|
||||
|
||||
def render_content(self, wb_url, kwargs, environ):
|
||||
wb_url = wb_url.replace('#', '%23')
|
||||
wb_url = WbUrl(wb_url)
|
||||
|
||||
history_page = environ.pop('HTTP_X_WOMBAT_HISTORY_PAGE', '')
|
||||
if history_page:
|
||||
wb_url.url = history_page
|
||||
@ -321,13 +330,13 @@ class RewriterApp(object):
|
||||
|
||||
is_timegate = self._check_accept_dt(wb_url, environ)
|
||||
|
||||
host_prefix = self.get_host_prefix(environ)
|
||||
self.prepare_env(environ)
|
||||
|
||||
host_prefix = environ['pywb.host_prefix']
|
||||
rel_prefix = self.get_rel_prefix(environ)
|
||||
full_prefix = host_prefix + rel_prefix
|
||||
environ['pywb.host_prefix'] = host_prefix
|
||||
pywb_static_prefix = host_prefix + environ.get('pywb.app_prefix', '') + '/' + self.static_prefix
|
||||
environ['pywb.static_prefix'] = pywb_static_prefix
|
||||
pywb_static_prefix += '/'
|
||||
|
||||
pywb_static_prefix = environ['pywb.static_prefix'] + '/'
|
||||
is_proxy = ('wsgiprox.proxy_host' in environ)
|
||||
|
||||
# if OPTIONS in proxy mode, just generate the proxy responss
|
||||
|
@ -1,4 +1,4 @@
|
||||
__version__ = '2.6.2'
|
||||
__version__ = '2.6.3'
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(__version__)
|
||||
|
@ -12,12 +12,25 @@ class TestWbIntegration(BaseConfigTest):
|
||||
def test_home(self):
|
||||
resp = self.testapp.get('/')
|
||||
self._assert_basic_html(resp)
|
||||
assert '<link rel="stylesheet" href="http://localhost:80/static/css/base.css"' in resp.text
|
||||
assert '/pywb' in resp.text
|
||||
|
||||
def test_home_custom_prefix(self):
|
||||
resp = self.testapp.get('/', extra_environ={'SCRIPT_NAME': '/wayback'})
|
||||
self._assert_basic_html(resp)
|
||||
assert '<link rel="stylesheet" href="http://localhost:80/wayback/static/css/base.css"' in resp.text
|
||||
assert '/pywb' in resp.text
|
||||
|
||||
def test_pywb_root(self):
|
||||
resp = self.testapp.get('/pywb/')
|
||||
self._assert_basic_html(resp)
|
||||
assert '<link rel="stylesheet" href="/static/css/base.css"' in resp.text
|
||||
assert '<link rel="stylesheet" href="http://localhost:80/static/css/base.css"' in resp.text
|
||||
assert 'Search' in resp.text
|
||||
|
||||
def test_pywb_root_custom_prefix(self):
|
||||
resp = self.testapp.get('/pywb/', extra_environ={'SCRIPT_NAME': '/wayback'})
|
||||
self._assert_basic_html(resp)
|
||||
assert '<link rel="stylesheet" href="http://localhost:80/wayback/static/css/base.css"' in resp.text
|
||||
assert 'Search' in resp.text
|
||||
|
||||
def test_pywb_root_head(self):
|
||||
|
2
wombat
2
wombat
@ -1 +1 @@
|
||||
Subproject commit e0567d5f7bbecd1687d46ee2c7883c0bfd39a6c2
|
||||
Subproject commit 72db79431401ad6d7449eb77c37a6a82b84113c8
|
Loading…
x
Reference in New Issue
Block a user