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

Commit bb4e840

Browse files
committed
Cleanup close logic.
1 parent e94a059 commit bb4e840

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

hyper/http20/connection.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,10 @@ def _stream_close_cb(self, stream_id):
547547
"""
548548
Called by a stream when it is closing, so that state can be cleared.
549549
"""
550-
del self.streams[stream_id]
550+
try:
551+
del self.streams[stream_id]
552+
except KeyError:
553+
pass
551554

552555
# The following two methods are the implementation of the context manager
553556
# protocol.

hyper/http20/response.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ def read(self, amt=None, decode_content=True):
129129
if self._stream.response_headers:
130130
self.headers.merge(self._stream.response_headers)
131131

132+
# We're at the end, close the connection.
133+
if response_complete:
134+
self.close()
135+
132136
return data
133137

134138
def read_chunked(self, decode_content=True):
@@ -155,6 +159,8 @@ def read_chunked(self, decode_content=True):
155159
if decode_content and self._decompressobj:
156160
yield self._decompressobj.flush()
157161

162+
self.close()
163+
158164
return
159165

160166
def fileno(self):

hyper/http20/stream.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,10 @@ def close(self, error_code=None):
286286
:param error_code: (optional) The error code to reset the stream with.
287287
:returns: Nothing.
288288
"""
289-
if not self.local_closed:
290-
self._conn.end_stream(self.stream_id)
291-
else:
289+
if not self.remote_closed:
292290
self._conn.reset_stream(self.stream_id, error_code or 0)
291+
self._send_cb(self._conn.data_to_send())
293292

294-
self._send_cb(self._conn.data_to_send())
295293
self._close_cb(self.stream_id)
296294

297295
@property

0 commit comments

Comments
 (0)