Skip to content

Commit

Permalink
HTTPServer: Support requests that are received in multiple chunks.
Browse files Browse the repository at this point in the history
  • Loading branch information
bdarnell committed Mar 16, 2014
1 parent 4f734dd commit e9c83cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions tornado/httpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class _ServerRequestAdapter(httputil.HTTPMessageDelegate):
def __init__(self, server, connection):
self.server = server
self.connection = connection
self._chunks = []

def headers_received(self, start_line, headers):
# HTTPRequest wants an IP, not a full socket address
Expand Down Expand Up @@ -192,10 +193,10 @@ def headers_received(self, start_line, headers):
headers=headers, remote_ip=remote_ip, protocol=protocol)

def data_received(self, chunk):
assert not self.request.body
self.request.body = chunk
self._chunks.append(chunk)

def finish(self):
self.request.body = b''.join(self._chunks)
self.request._parse_body()
self.server.request_callback(self.request)

Expand Down
6 changes: 4 additions & 2 deletions tornado/test/httpserver_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,10 @@ def test_chunked_request_body(self):
Transfer-Encoding: chunked
Content-Type: application/x-www-form-urlencoded
7
foo=bar
4
foo=
3
bar
0
""".replace(b"\n", b"\r\n"))
Expand Down

0 comments on commit e9c83cb

Please sign in to comment.