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

Commit

Permalink
Merge pull request #237 from tbetbetbe/development-reset-stream
Browse files Browse the repository at this point in the history
Modify how stream resets are reported.
  • Loading branch information
Lukasa committed Apr 27, 2016
2 parents 5704d26 + 6531ae9 commit 5d73ce1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
10 changes: 7 additions & 3 deletions hyper/http20/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from .stream import Stream
from .response import HTTP20Response, HTTP20Push
from .window import FlowControlManager
from .exceptions import ConnectionError
from .exceptions import ConnectionError, StreamResetError
from . import errors

import errno
Expand Down Expand Up @@ -186,8 +186,12 @@ def request(self, method, url, body=None, headers=None):
return stream_id

def _get_stream(self, stream_id):
return (self.streams[stream_id] if stream_id is not None
else self.recent_stream)
if stream_id is None:
return self.recent_stream
elif stream_id in self.reset_streams or stream_id not in self.streams:
raise StreamResetError("Stream forcefully closed")
else:
return self.streams[stream_id]

def get_response(self, stream_id=None):
"""
Expand Down
3 changes: 1 addition & 2 deletions hyper/http20/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
the stream by the endpoint that initiated the stream.
"""
from ..common.headers import HTTPHeaderMap
from .exceptions import StreamResetError
from .util import h2_safe_headers
import logging

Expand Down Expand Up @@ -201,7 +200,7 @@ def receive_reset(self, event):
Stream forcefully reset.
"""
self.remote_closed = True
raise StreamResetError("Stream forcefully closed")
self._close_cb(self.stream_id)

def get_headers(self):
"""
Expand Down
14 changes: 7 additions & 7 deletions test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ def socket_handler(listener):
conn._recv_cb()

# However, attempting to get the response should.
with pytest.raises(KeyError):
with pytest.raises(StreamResetError):
conn.get_response(stream_id)

# Awesome, we're done now.
Expand Down Expand Up @@ -716,14 +716,14 @@ def socket_handler(listener):
conn = self.get_connection()
conn.request('GET', '/')

# Now, eat the RstStream frames. The first one throws a
# StreamResetError.
with pytest.raises(StreamResetError):
conn._single_read()

# The next should throw no exception.
# Now, eat the Rst frames. These should not cause an exception.
conn._single_read()
conn._single_read()

# However, attempting to get the response should.
with pytest.raises(StreamResetError):
conn.get_response(1)

assert conn.reset_streams == set([1])

# Awesome, we're done now.
Expand Down

0 comments on commit 5d73ce1

Please sign in to comment.