Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #325 from ex3me0/development
Browse files Browse the repository at this point in the history
HTTP/1.1 parser fix, when response contains empty reason
  • Loading branch information
Lukasa committed May 30, 2017
2 parents acc6f20 + ed270c0 commit 496f3a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion hyper/http11/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def parse_response(self, buffer):
if index == -1:
return None

version, status, reason = temp_buffer[0:index].split(None, 2)
version, status, reason = (
temp_buffer[0:index].split(None, 2) + [b''])[:3]
if not version.startswith(b'HTTP/1.'):
raise ParseError("Not HTTP/1.X!")

Expand Down
17 changes: 17 additions & 0 deletions test/test_http11.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,23 @@ def test_chunked_overrides_body(self):

assert received == expected

def test_response_with_empty_reason(self):
c = HTTP11Connection('httpbin.org')
c._sock = sock = DummySocket()

sock._buffer = BytesIO(
b"HTTP/1.1 201 \r\n"
b"Connection: close\r\n"
b"Server: Socket\r\n"
b"Content-Length: 0\r\n"
b"\r\n"
)

r = c.get_response()

assert r.status == 201
assert r.reason == b''

def test_get_response(self):
c = HTTP11Connection('httpbin.org')
c._sock = sock = DummySocket()
Expand Down

0 comments on commit 496f3a0

Please sign in to comment.