|
27 | 27 | from .exceptions import (
|
28 | 28 | ProtocolError, NoSuchStreamError, FlowControlError, FrameTooLargeError,
|
29 | 29 | TooManyStreamsError, StreamClosedError, StreamIDTooLowError,
|
30 |
| - NoAvailableStreamIDError, UnsupportedFrameError, RFC1122Error |
| 30 | + NoAvailableStreamIDError, RFC1122Error |
31 | 31 | )
|
32 | 32 | from .frame_buffer import FrameBuffer
|
33 | 33 | from .settings import (
|
|
38 | 38 | from .utilities import validate_headers, guard_increment_window
|
39 | 39 |
|
40 | 40 |
|
| 41 | +try: |
| 42 | + from hyperframe.frame import ExtensionFrame |
| 43 | +except ImportError: # Platform-specific: Hyperframe < 5.0.0 |
| 44 | + # If the frame doesn't exist, that's just fine: we'll define it ourselves |
| 45 | + # and the method will just never be called. |
| 46 | + class ExtensionFrame(object): |
| 47 | + pass |
| 48 | + |
| 49 | + |
41 | 50 | class ConnectionState(Enum):
|
42 | 51 | IDLE = 0
|
43 | 52 | CLIENT_OPEN = 1
|
@@ -358,6 +367,7 @@ def __init__(self, client_side=True, header_encoding='utf-8'):
|
358 | 367 | GoAwayFrame: self._receive_goaway_frame,
|
359 | 368 | ContinuationFrame: self._receive_naked_continuation,
|
360 | 369 | AltSvcFrame: self._receive_alt_svc_frame,
|
| 370 | + ExtensionFrame: self._receive_unknown_frame |
361 | 371 | }
|
362 | 372 |
|
363 | 373 | def _prepare_for_sending(self, frames):
|
@@ -1352,10 +1362,6 @@ def _receive_frame(self, frame):
|
1352 | 1362 | if frame.stream_id not in self._reset_streams:
|
1353 | 1363 | raise
|
1354 | 1364 | events = []
|
1355 |
| - except KeyError as e: # pragma: no cover |
1356 |
| - # We don't have a function for handling this frame. Let's call this |
1357 |
| - # a PROTOCOL_ERROR and exit. |
1358 |
| - raise UnsupportedFrameError("Unexpected frame: %s" % frame) |
1359 | 1365 | else:
|
1360 | 1366 | self._prepare_for_sending(frames)
|
1361 | 1367 |
|
@@ -1713,6 +1719,18 @@ def _receive_alt_svc_frame(self, frame):
|
1713 | 1719 |
|
1714 | 1720 | return frames, events
|
1715 | 1721 |
|
| 1722 | + def _receive_unknown_frame(self, frame): |
| 1723 | + """ |
| 1724 | + We have received a frame that we do not understand. This is almost |
| 1725 | + certainly an extension frame, though it's impossible to be entirely |
| 1726 | + sure. |
| 1727 | +
|
| 1728 | + RFC 7540 § 5.5 says that we MUST ignore unknown frame types: so we |
| 1729 | + do. |
| 1730 | + """ |
| 1731 | + # We don't do anything here. |
| 1732 | + return [], [] |
| 1733 | + |
1716 | 1734 | def _local_settings_acked(self):
|
1717 | 1735 | """
|
1718 | 1736 | Handle the local settings being ACKed, update internal state.
|
|
0 commit comments