From 129fe71f83454419cd3a01ebb7e7fb55e0c023c7 Mon Sep 17 00:00:00 2001 From: Maik Hoepfel Date: Tue, 21 Mar 2017 13:20:57 +0800 Subject: [PATCH] Fix: Always call Request.write() The spec says 'content' is an optional key, defaulting to b''. But before this commit, if 'content' wasn't specified, Request.write() was not called. In conjunction with setting 'more_content' to True, this would result in nothing being written on the transport. If 'content' was set to b'' instead, the HTTP preamble and any headers were written as expected. That smells like a bug, so I'm making sure we're always calling Request.write(). --- daphne/http_protocol.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/daphne/http_protocol.py b/daphne/http_protocol.py index e466219..2de1f85 100755 --- a/daphne/http_protocol.py +++ b/daphne/http_protocol.py @@ -240,9 +240,10 @@ class WebRequest(http.Request): header = header.encode("latin1") self.responseHeaders.addRawHeader(header, value) logger.debug("HTTP %s response started for %s", message['status'], self.reply_channel) + # Write out body - if "content" in message: - http.Request.write(self, message['content']) + http.Request.write(self, message.get('content', b'')) + # End if there's no more content if not message.get("more_content", False): self.finish()