Response chunk support

This commit is contained in:
Andrew Godwin 2016-01-02 18:41:02 -08:00
parent 0f5fe8b274
commit c61664dd3c

View File

@ -29,6 +29,7 @@ class WebRequest(http.Request):
# Tell factory we're that channel's client # Tell factory we're that channel's client
self.last_keepalive = time.time() self.last_keepalive = time.time()
self.factory.reply_protocols[self.reply_channel] = self self.factory.reply_protocols[self.reply_channel] = self
self._got_response_start = False
def process(self): def process(self):
# Get upgrade header # Get upgrade header
@ -104,6 +105,10 @@ class WebRequest(http.Request):
""" """
Writes a received HTTP response back out to the transport. Writes a received HTTP response back out to the transport.
""" """
if "status" in message:
if self._got_response_start:
raise ValueError("Got multiple Response messages!")
self._got_response_start = True
# Write code # Write code
self.setResponseCode(message['status']) self.setResponseCode(message['status'])
# Write headers # Write headers
@ -112,8 +117,12 @@ class WebRequest(http.Request):
# Write out body # Write out body
if "content" in message: if "content" in message:
http.Request.write(self, message['content'].encode("utf8")) http.Request.write(self, message['content'].encode("utf8"))
# End if there's no more content
if not message.get("more_content", False):
self.finish() self.finish()
logging.debug("HTTP %s response for %s", message['status'], self.reply_channel) logging.debug("HTTP %s response for %s", message['status'], self.reply_channel)
else:
logging.debug("HTTP %s response chunk for %s", message['status'], self.reply_channel)
class HTTPProtocol(http.HTTPChannel): class HTTPProtocol(http.HTTPChannel):