fix (render.py): fix non-ascii characters in HTTP headers.

HTTP headers need to be ascii or Gunicorn throws an exception.
The error handler 'xmlcharrefreplace' is chosen for no particular
reason.
This commit is contained in:
Andrew McLeod 2019-09-16 23:11:01 +01:00
parent 63cb27b924
commit c57710052e

View file

@ -125,12 +125,12 @@ def build_response(path, data, http_status_code, headers=None):
response = Response()
response.data = set_content_type(response, data, path)
response.status_code = http_status_code
response.headers["X-Page-Name"] = path.encode("utf-8")
response.headers["X-Page-Name"] = path.encode("ascii", errors="xmlcharrefreplace")
response.headers["X-From-Cache"] = frappe.local.response.from_cache or False
if headers:
for key, val in iteritems(headers):
response.headers[key] = val.encode("utf-8")
response.headers[key] = val.encode("ascii", errors="xmlcharrefreplace")
return response