mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
proxy mode: replay improvements for content not captured via proxy mode (#520)
- if preflight OPTIONS request, respond directly (don't attempt OPTIONS capture lookup) - if preflight CORS request, ensure response has appropriate CORS headers, even if not captured - wombat: update to latest wombat with updated Date() fixed timezone in proxy mode - bump version to 2.4.0rc3
This commit is contained in:
parent
c7fdfe72a7
commit
30680803e8
@ -326,6 +326,10 @@ class RewriterApp(object):
|
|||||||
'pywb.static_prefix', '/static/')
|
'pywb.static_prefix', '/static/')
|
||||||
is_proxy = ('wsgiprox.proxy_host' in environ)
|
is_proxy = ('wsgiprox.proxy_host' in environ)
|
||||||
|
|
||||||
|
# if OPTIONS in proxy mode, just generate the proxy responss
|
||||||
|
if is_proxy and self.is_preflight(environ):
|
||||||
|
return WbResponse.options_response(environ)
|
||||||
|
|
||||||
environ['pywb.host_prefix'] = host_prefix
|
environ['pywb.host_prefix'] = host_prefix
|
||||||
|
|
||||||
if self.use_js_obj_proxy:
|
if self.use_js_obj_proxy:
|
||||||
@ -551,6 +555,9 @@ class RewriterApp(object):
|
|||||||
|
|
||||||
response = WbResponse(status_headers, gen)
|
response = WbResponse(status_headers, gen)
|
||||||
|
|
||||||
|
if is_proxy and environ.get('HTTP_ORIGIN'):
|
||||||
|
response.add_access_control_headers(environ)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def format_response(self, response, wb_url, full_prefix, is_timegate, is_proxy):
|
def format_response(self, response, wb_url, full_prefix, is_timegate, is_proxy):
|
||||||
@ -817,6 +824,19 @@ class RewriterApp(object):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def is_preflight(self, environ):
|
||||||
|
if environ.get('REQUEST_METHOD') != 'OPTIONS':
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not environ.get('HTTP_ORIGIN'):
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not environ.get('HTTP_ACCESS_CONTROL_REQUEST_METHOD') and not environ.get('HTTP_ACCESS_CONTROL_REQUEST_HEADERS'):
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def get_base_url(self, wb_url, kwargs):
|
def get_base_url(self, wb_url, kwargs):
|
||||||
type_ = kwargs.get('type')
|
type_ = kwargs.get('type')
|
||||||
return self.paths[type_].format(**kwargs)
|
return self.paths[type_].format(**kwargs)
|
||||||
|
@ -186,14 +186,14 @@ class WbResponse(object):
|
|||||||
allowed_methods = allowed_methods + ', ' + r_method
|
allowed_methods = allowed_methods + ', ' + r_method
|
||||||
acr_headers = env.get('HTTP_ACCESS_CONTROL_REQUEST_HEADERS')
|
acr_headers = env.get('HTTP_ACCESS_CONTROL_REQUEST_HEADERS')
|
||||||
if acr_headers is not None:
|
if acr_headers is not None:
|
||||||
self.status_headers.add_header('Access-Control-Allow-Headers', acr_headers)
|
self.status_headers.replace_header('Access-Control-Allow-Headers', acr_headers)
|
||||||
allowed_origin = env.get('HTTP_ORIGIN', env.get('HTTP_REFERER', allowed_origin))
|
allowed_origin = env.get('HTTP_ORIGIN', env.get('HTTP_REFERER', allowed_origin))
|
||||||
if allowed_origin is None:
|
if allowed_origin is None:
|
||||||
allowed_origin = '*'
|
allowed_origin = '*'
|
||||||
self.status_headers.replace_header('Access-Control-Allow-Origin', allowed_origin)
|
self.status_headers.replace_header('Access-Control-Allow-Origin', allowed_origin)
|
||||||
self.status_headers.add_header('Access-Control-Allow-Methods', allowed_methods)
|
self.status_headers.replace_header('Access-Control-Allow-Methods', allowed_methods)
|
||||||
self.status_headers.add_header('Access-Control-Allow-Credentials', 'true')
|
self.status_headers.replace_header('Access-Control-Allow-Credentials', 'true')
|
||||||
self.status_headers.add_header('Access-Control-Max-Age', '1800')
|
self.status_headers.replace_header('Access-Control-Max-Age', '1800')
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1,4 +1,4 @@
|
|||||||
__version__ = '2.4.0rc0'
|
__version__ = '2.4.0rc3'
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print(__version__)
|
print(__version__)
|
||||||
|
@ -83,6 +83,20 @@ class TestProxy(BaseTestProxy):
|
|||||||
assert res.headers['Memento-Datetime'] == 'Mon, 27 Jan 2014 17:12:51 GMT'
|
assert res.headers['Memento-Datetime'] == 'Mon, 27 Jan 2014 17:12:51 GMT'
|
||||||
assert 'Content-Location' not in res.headers
|
assert 'Content-Location' not in res.headers
|
||||||
|
|
||||||
|
def test_proxy_replay_cors(self, scheme):
|
||||||
|
res = requests.get('{0}://example.com/'.format(scheme),
|
||||||
|
proxies=self.proxies,
|
||||||
|
verify=self.root_ca_file,
|
||||||
|
headers={'Origin': '{0}://api.example.com/'.format(scheme)})
|
||||||
|
|
||||||
|
assert 'Example Domain' in res.text
|
||||||
|
|
||||||
|
assert res.headers['Access-Control-Allow-Methods'] == 'GET, POST, PUT, OPTIONS, DELETE, PATCH, HEAD, TRACE, CONNECT'
|
||||||
|
assert res.headers['Access-Control-Allow-Credentials'] == 'true'
|
||||||
|
assert res.headers['Access-Control-Allow-Origin'] == '{0}://api.example.com/'.format(scheme)
|
||||||
|
|
||||||
|
assert 'Content-Location' not in res.headers
|
||||||
|
|
||||||
def test_proxy_replay_change_dt(self, scheme):
|
def test_proxy_replay_change_dt(self, scheme):
|
||||||
headers = {'Accept-Datetime': 'Mon, 26 Dec 2011 17:12:51 GMT'}
|
headers = {'Accept-Datetime': 'Mon, 26 Dec 2011 17:12:51 GMT'}
|
||||||
res = requests.get('{0}://example.com/'.format(scheme),
|
res = requests.get('{0}://example.com/'.format(scheme),
|
||||||
|
2
wombat
2
wombat
@ -1 +1 @@
|
|||||||
Subproject commit 50ff6e3ed3afc2fd27f82bae4f5f20194f1bfc53
|
Subproject commit c3276154de61196c0c34d9f5f1242706d6e407b6
|
Loading…
x
Reference in New Issue
Block a user