Skip to content

Commit

Permalink
try to remove headers with illegal characters. arquivo/pwa-technologi…
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbicho committed Apr 30, 2020
1 parent 92e459b commit 6b014d0
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions pywb/apps/wbrequestresponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,33 @@ def options_response(env):
response.add_access_control_headers(env=env)
return response

def try_fix_errors(self):
"""Utility method to try remove faulty headers from response.
:return:
:rtype: None
"""
for header in self.status_headers.headers:
try:
header[1].encode('latin1')
except UnicodeError:
self.status_headers.remove_header(header[0])

def __call__(self, env, start_response):
"""Callable definition to allow WbResponse control over how the response is sent
:param dict env: The WSGI environment dictionary
:param function start_response: The WSGI start_response function
:return: The response body
"""
start_response(self.status_headers.statusline,
self.status_headers.headers)
try:
start_response(self.status_headers.statusline,
self.status_headers.headers)
except UnicodeError:
self.try_fix_errors()
start_response(self.status_headers.statusline,
self.status_headers.headers)

request_method = env['REQUEST_METHOD']
if request_method == 'HEAD' or request_method == 'OPTIONS' or self.status_headers.statusline.startswith('304'):
no_except_close(self.body)
Expand Down

0 comments on commit 6b014d0

Please sign in to comment.