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

Commit e6bf4a8

Browse files
committed
Confirm we reset incomplete streams.
1 parent bb4e840 commit e6bf4a8

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

hyper/http20/stream.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,12 @@ 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.remote_closed:
289+
# FIXME: I think this is overbroad, but for now it's probably ok.
290+
if not (self.remote_closed and self.local_closed):
290291
self._conn.reset_stream(self.stream_id, error_code or 0)
291292
self._send_cb(self._conn.data_to_send())
293+
self.remote_closed = True
294+
self.local_closed = True
292295

293296
self._close_cb(self.stream_id)
294297

test/test_hyper.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,28 @@ def test_sending_file(self, frame_buffer):
463463
with open(__file__, 'rb') as f:
464464
assert f.read() == sent_data
465465

466+
def test_closing_incomplete_stream(self, frame_buffer):
467+
# Prepare a socket so we can open a stream.
468+
sock = DummySocket()
469+
c = HTTP20Connection('www.google.com')
470+
c._sock = sock
471+
472+
# Send a request that involves uploading some data, but don't finish.
473+
c.putrequest('POST', '/')
474+
c.endheaders(message_body=b'some data', final=False)
475+
476+
# Close the stream.
477+
c.streams[1].close()
478+
479+
# Get all the frames
480+
frame_buffer.add_data(b''.join(sock.queue))
481+
frames = list(frame_buffer)
482+
483+
# The last one should be a RST_STREAM frame.
484+
f = frames[-1]
485+
assert isinstance(f, RstStreamFrame)
486+
assert 1 not in c.streams
487+
466488

467489
class TestServerPush(object):
468490
def setup_method(self, method):

0 commit comments

Comments
 (0)