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

Commit 496f3a0

Browse files
authored
Merge pull request #325 from ex3me0/development
HTTP/1.1 parser fix, when response contains empty reason
2 parents acc6f20 + ed270c0 commit 496f3a0

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

hyper/http11/parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def parse_response(self, buffer):
4949
if index == -1:
5050
return None
5151

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

test/test_http11.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,23 @@ def test_chunked_overrides_body(self):
329329

330330
assert received == expected
331331

332+
def test_response_with_empty_reason(self):
333+
c = HTTP11Connection('httpbin.org')
334+
c._sock = sock = DummySocket()
335+
336+
sock._buffer = BytesIO(
337+
b"HTTP/1.1 201 \r\n"
338+
b"Connection: close\r\n"
339+
b"Server: Socket\r\n"
340+
b"Content-Length: 0\r\n"
341+
b"\r\n"
342+
)
343+
344+
r = c.get_response()
345+
346+
assert r.status == 201
347+
assert r.reason == b''
348+
332349
def test_get_response(self):
333350
c = HTTP11Connection('httpbin.org')
334351
c._sock = sock = DummySocket()

0 commit comments

Comments
 (0)