Allow already encoded answers

This commit is contained in:
Unrud 2017-05-07 08:17:35 +02:00
parent bc49542a62
commit f1a9cf7694

View File

@ -289,8 +289,10 @@ class Application:
headers = dict(headers)
# Set content length
if answer:
self.logger.debug("Response content:\n%s", answer)
answer = answer.encode(self.encoding)
if hasattr(answer, "encode"):
self.logger.debug("Response content:\n%s", answer)
headers["Content-Type"] += "; charset=%s" % self.encoding
answer = answer.encode(self.encoding)
accept_encoding = [
encoding.strip() for encoding in
environ.get("HTTP_ACCEPT_ENCODING", "").split(",")
@ -302,7 +304,6 @@ class Application:
headers["Content-Encoding"] = "gzip"
headers["Content-Length"] = str(len(answer))
headers["Content-Type"] += "; charset=%s" % self.encoding
# Add extra headers set in configuration
if self.configuration.has_section("headers"):