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

proxy support: update for wsgiprox==1.2, transfer-encoding/buffering support now part of wsgiprox

frame insert: set 'iframe_url' to full rewritten url, or in proxy mode, original url with scheme matching current scheme
This commit is contained in:
Ilya Kreymer 2017-04-24 15:08:42 -07:00
parent 15a7b15d44
commit 7ceeb32531
3 changed files with 15 additions and 25 deletions

View File

@ -31,7 +31,7 @@ html, body
</head>
<body style="margin: 0px; padding: 0px;">
<div class="wb_iframe_div">
<iframe id="replay_iframe" src="{{ wbrequest.wb_prefix + embed_url }}" onload="" frameborder="0" seamless="seamless" scrolling="yes" class="wb_iframe"></iframe>
<iframe id="replay_iframe" src="{{ iframe_url }}" onload="" frameborder="0" seamless="seamless" scrolling="yes" class="wb_iframe"></iframe>
</div>
</body>
</html>

View File

@ -20,7 +20,7 @@ from pywb.webagg.utils import BUFF_SIZE
from pywb.cdx.cdxobject import CDXObject
from pywb.framework.wbrequestresponse import WbResponse
from pywb.webagg.utils import MementoUtils, buffer_iter, chunk_encode_iter
from pywb.webagg.utils import MementoUtils
from werkzeug.http import HTTP_STATUS_CODES
from six.moves.urllib.parse import urlencode, urlsplit, urlunsplit
@ -122,10 +122,10 @@ class RewriterApp(object):
return WbResponse.text_response(resp, content_type=content_type)
is_proxy = ('wsgiprox.fixed_host' in environ)
is_proxy = ('wsgiprox.proxy_host' in environ)
if is_proxy:
environ['pywb_proxy_magic'] = environ['wsgiprox.fixed_host']
environ['pywb_proxy_magic'] = environ['wsgiprox.proxy_host']
urlrewriter = SchemeOnlyUrlRewriter(wb_url, '')
framed_replay = False
@ -295,29 +295,11 @@ class RewriterApp(object):
response = WbResponse(status_headers, gen)
if is_proxy:
self.prepare_proxy_response(response, environ)
response.status_headers.remove_header('Content-Security-Policy')
response.status_headers.remove_header('X-Frame-Options')
return response
def prepare_proxy_response(self, response, environ):
response.status_headers.remove_header('Content-Security-Policy')
res = response.status_headers.get_header('content-length')
try:
if int(res) > 0:
return
except:
pass
# need to either chunk or buffer to get content-length
if environ.get('SERVER_PROTOCOL') == 'HTTP/1.1':
response.status_headers.remove_header('content-length')
response.status_headers.headers.append(('Transfer-Encoding', 'chunked'))
response.body = chunk_encode_iter(response.body)
else:
response.body = buffer_iter(response.status_headers,
response.body)
def _add_memento_links(self, urlrewriter, full_prefix, memento_dt, status_headers):
wb_url = urlrewriter.wburl
status_headers.headers.append(('Memento-Datetime', memento_dt))
@ -457,7 +439,7 @@ class RewriterApp(object):
scheme = environ['wsgi.url_scheme'] + '://'
# proxy
host = environ.get('wsgiprox.fixed_host')
host = environ.get('wsgiprox.proxy_host')
if host:
return scheme + host

View File

@ -176,6 +176,13 @@ class TopFrameView(BaseInsertView):
else:
timestamp = timestamp_now()
if 'wsgiprox.proxy_host' in env:
if not wb_url.url.startswith(env['wsgi.url_scheme'] + ':'):
wb_url.url = env['wsgi.url_scheme'] + ':' + wb_url.url.split(':', 1)[-1]
iframe_url = wb_url.url
else:
iframe_url = wb_prefix + embed_url
wbrequest = {'host_prefix': host_prefix,
'wb_prefix': wb_prefix,
'wb_url': wb_url,
@ -186,6 +193,7 @@ class TopFrameView(BaseInsertView):
}
params = dict(embed_url=embed_url,
iframe_url=iframe_url,
wbrequest=wbrequest,
timestamp=timestamp,
url=wb_url.get_url(),