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

Commit 03d14b6

Browse files
committed
Do not raise protocol error
If an unexpected stream id is received there is no need to punish the user by raising a protocol error. Instead we prefer to add a warning message and close that particular stream by sending a reset frame.
1 parent 04438f9 commit 03d14b6

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

hyper/http20/connection.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,8 @@ def _consume_frame_payload(self, frame, data):
593593
f = RstStreamFrame(frame.stream_id)
594594
f.error_code = 1 # PROTOCOL_ERROR
595595
self._send_cb(f)
596-
error_string = ("Unexpected stream identifier %d" %
597-
(frame.stream_id))
598-
raise ProtocolError(error_string)
596+
log.warning("Unexpected stream identifier %d" %
597+
(frame.stream_id))
599598
else:
600599
self.receive_frame(frame)
601600

hyper/http20/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
the array.
99
1010
The current registry is available at:
11-
https://tools.ietf.org/html/draft-ietf-httpbis-http2-17#section-11.4
11+
https://tools.ietf.org/html/rfc7540#section-11.4
1212
"""
1313

1414
NO_ERROR = {'Name': 'NO_ERROR',

test/test_hyper.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,9 +1272,16 @@ def data_callback(frame):
12721272

12731273
f = DataFrame(-1)
12741274
data = memoryview(b"hi there sir")
1275+
c._consume_frame_payload(f, data)
1276+
1277+
# If we receive an unexpected stream id then we cancel the stream
1278+
# by sending a reset stream that contains the protocol error code (1)
1279+
f = frames[0]
1280+
assert len(frames) == 1
1281+
assert f.stream_id == -1
1282+
assert isinstance(f, RstStreamFrame)
1283+
assert f.error_code == 1 # PROTOCOL_ERROR
12751284

1276-
with pytest.raises(ProtocolError):
1277-
c._consume_frame_payload(f, data)
12781285

12791286
# Some utility classes for the tests.
12801287
class NullEncoder(object):

0 commit comments

Comments
 (0)