Fix logging and log action around chunked HTTP responses

This commit is contained in:
Andrew Godwin 2016-02-20 23:33:50 +00:00
parent b9412f8e82
commit 1709522162

View File

@ -143,21 +143,22 @@ class WebRequest(http.Request):
# Write headers # Write headers
for header, value in message.get("headers", {}): for header, value in message.get("headers", {}):
self.setHeader(header.encode("utf8"), value) self.setHeader(header.encode("utf8"), value)
logger.debug("HTTP %s response started for %s", message['status'], self.reply_channel)
# Write out body # Write out body
if "content" in message: if "content" in message:
http.Request.write(self, message['content']) http.Request.write(self, message['content'])
# End if there's no more content # End if there's no more content
if not message.get("more_content", False): if not message.get("more_content", False):
self.finish() self.finish()
logger.debug("HTTP %s response for %s", message['status'], self.reply_channel) logger.debug("HTTP response complete for %s", self.reply_channel)
else:
logger.debug("HTTP %s response chunk for %s", message['status'], self.reply_channel)
self.factory.log_action("http", "complete", { self.factory.log_action("http", "complete", {
"path": self.path.decode("ascii"), "path": self.path.decode("ascii"),
"status": message['status'], "status": self.code,
"method": self.method.decode("ascii"), "method": self.method.decode("ascii"),
"client": "%s:%s" % (self.client.host, self.client.port), "client": "%s:%s" % (self.client.host, self.client.port),
}) })
else:
logger.debug("HTTP response chunk for %s", self.reply_channel)
class HTTPProtocol(http.HTTPChannel): class HTTPProtocol(http.HTTPChannel):