28
28
from .exceptions import (
29
29
ProtocolError , NoSuchStreamError , FlowControlError , FrameTooLargeError ,
30
30
TooManyStreamsError , StreamClosedError , StreamIDTooLowError ,
31
- NoAvailableStreamIDError , UnsupportedFrameError , RFC1122Error ,
32
- DenialOfServiceError
31
+ NoAvailableStreamIDError , RFC1122Error , DenialOfServiceError
33
32
)
34
33
from .frame_buffer import FrameBuffer
35
34
from .settings import (
@@ -49,6 +48,15 @@ class OversizedHeaderListError(Exception):
49
48
pass
50
49
51
50
51
+ try :
52
+ from hyperframe .frame import ExtensionFrame
53
+ except ImportError : # Platform-specific: Hyperframe < 5.0.0
54
+ # If the frame doesn't exist, that's just fine: we'll define it ourselves
55
+ # and the method will just never be called.
56
+ class ExtensionFrame (object ):
57
+ pass
58
+
59
+
52
60
class ConnectionState (Enum ):
53
61
IDLE = 0
54
62
CLIENT_OPEN = 1
@@ -403,6 +411,7 @@ def __init__(self, client_side=True, header_encoding='utf-8', config=None):
403
411
GoAwayFrame : self ._receive_goaway_frame ,
404
412
ContinuationFrame : self ._receive_naked_continuation ,
405
413
AltSvcFrame : self ._receive_alt_svc_frame ,
414
+ ExtensionFrame : self ._receive_unknown_frame
406
415
}
407
416
408
417
def _prepare_for_sending (self , frames ):
@@ -1491,10 +1500,6 @@ def _receive_frame(self, frame):
1491
1500
if frame .stream_id not in self ._reset_streams :
1492
1501
raise
1493
1502
events = []
1494
- except KeyError as e : # pragma: no cover
1495
- # We don't have a function for handling this frame. Let's call this
1496
- # a PROTOCOL_ERROR and exit.
1497
- raise UnsupportedFrameError ("Unexpected frame: %s" % frame )
1498
1503
else :
1499
1504
self ._prepare_for_sending (frames )
1500
1505
@@ -1829,6 +1834,18 @@ def _receive_alt_svc_frame(self, frame):
1829
1834
1830
1835
return frames , events
1831
1836
1837
+ def _receive_unknown_frame (self , frame ):
1838
+ """
1839
+ We have received a frame that we do not understand. This is almost
1840
+ certainly an extension frame, though it's impossible to be entirely
1841
+ sure.
1842
+
1843
+ RFC 7540 § 5.5 says that we MUST ignore unknown frame types: so we
1844
+ do.
1845
+ """
1846
+ # We don't do anything here.
1847
+ return [], []
1848
+
1832
1849
def _local_settings_acked (self ):
1833
1850
"""
1834
1851
Handle the local settings being ACKed, update internal state.
0 commit comments