Skip to content

Commit

Permalink
Fix BadStatusLine caused by extra CRLF after POST data #1792
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Jun 18, 2017
1 parent 6dcb632 commit bbdffb7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -34,6 +34,8 @@ Changes

- Support `deflate` encoding implemented in `httpbin.org/deflate` #1918

- Fix BadStatusLine caused by extra `CRLF` after `POST` data #1792


2.1.0 (2017-05-26)
------------------
Expand Down
5 changes: 5 additions & 0 deletions aiohttp/http_parser.py
Expand Up @@ -117,6 +117,11 @@ def feed_data(self, data,
# and split by lines
if self._payload_parser is None and not self._upgraded:
pos = data.find(SEP, start_pos)
# consume \r\n
if pos == start_pos and not self._lines:
start_pos = pos + 2
continue

if pos >= start_pos:
# line found
self._lines.append(data[start_pos:pos])
Expand Down
10 changes: 10 additions & 0 deletions tests/test_http_parser.py
Expand Up @@ -97,6 +97,16 @@ def test_parse_body(parser):
assert body == b'body'


@asyncio.coroutine
def test_parse_body_with_CRLF(parser):
text = b'\r\nGET /test HTTP/1.1\r\nContent-Length: 4\r\n\r\nbody'
messages, upgrade, tail = parser.feed_data(text)
assert len(messages) == 1
_, payload = messages[0]
body = yield from payload.read(4)
assert body == b'body'


def test_parse_delayed(parser):
text = b'GET /test HTTP/1.1\r\n'
messages, upgrade, tail = parser.feed_data(text)
Expand Down

0 comments on commit bbdffb7

Please sign in to comment.