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

Commit 5998a14

Browse files
committed
More testing of the response object.
1 parent 2a0620c commit 5998a14

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

hyper/http11/response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self, code, reason, headers, sock):
4242
# bother checking for content-length, we just keep reading until
4343
# we no longer can.
4444
self._expect_close = False
45-
if b'close' in self.headers.get('connection', []):
45+
if b'close' in self.headers.get(b'connection', []):
4646
self._expect_close = True
4747

4848
# The expected length of the body.

test/test_http11.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import hyper
1616
from hyper.http11.connection import HTTP11Connection
1717
from hyper.http11.response import HTTP11Response
18+
from hyper.http20.exceptions import ConnectionResetError
1819
from hyper.common.headers import HTTPHeaderMap
1920
from hyper.compat import bytes
2021

@@ -320,6 +321,28 @@ def test_short_circuit_read(self):
320321

321322
assert r.read() == b''
322323

324+
def test_aborted_reads(self):
325+
d = DummySocket()
326+
r = HTTP11Response(200, 'OK', {b'content-length': [b'15']}, d)
327+
328+
with pytest.raises(ConnectionResetError):
329+
r.read()
330+
331+
def test_read_expect_close(self):
332+
d = DummySocket()
333+
r = HTTP11Response(200, 'OK', {b'connection': [b'close']}, d)
334+
335+
assert r.read() == b''
336+
337+
def test_response_as_context_manager(self):
338+
r = HTTP11Response(
339+
200, 'OK', {b'content-length': [b'0']}, DummySocket()
340+
)
341+
342+
with r:
343+
assert r.read() == b''
344+
345+
assert r._sock == None
323346

324347
class DummySocket(object):
325348
def __init__(self):

0 commit comments

Comments
 (0)