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

Commit 9298d4e

Browse files
committed
Close streams when they're exhausted.
1 parent a4a55a7 commit 9298d4e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

hyper/http20/response.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,24 +106,28 @@ def read(self, amt=None, decode_content=True):
106106
if amt is not None and amt <= len(self._data_buffer):
107107
data = self._data_buffer[:amt]
108108
self._data_buffer = self._data_buffer[amt:]
109-
flush_buffer = False
109+
response_complete = False
110110
elif amt is not None:
111111
read_amt = amt - len(self._data_buffer)
112112
self._data_buffer += self._stream._read(read_amt)
113113
data = self._data_buffer[:amt]
114114
self._data_buffer = self._data_buffer[amt:]
115-
flush_buffer = len(data) < amt
115+
response_complete = len(data) < amt
116116
else:
117117
data = b''.join([self._data_buffer, self._stream._read()])
118-
flush_buffer = True
118+
response_complete = True
119119

120120
# We may need to decode the body.
121121
if decode_content and self._decompressobj and data:
122122
data = self._decompressobj.decompress(data)
123123

124-
# If we're at the end of the request, flush the buffer.
125-
if decode_content and self._decompressobj and flush_buffer:
126-
data += self._decompressobj.flush()
124+
# If we're at the end of the request, we have some cleaning up to do.
125+
# Close the stream, and if necessary flush the buffer.
126+
if response_complete:
127+
if decode_content and self._decompressobj:
128+
data += self._decompressobj.flush()
129+
130+
self.close()
127131

128132
return data
129133

0 commit comments

Comments
 (0)