Skip to content

Commit 944b557

Browse files
committed
Define UnknownFrameReceived event
1 parent 3f5672c commit 944b557

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

docs/source/api.rst

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ Events
7777
.. autoclass:: h2.events.AlternativeServiceAvailable
7878
:members:
7979

80+
.. autoclass:: h2.events.UnknownFrameReceived
81+
:members:
82+
8083

8184
Exceptions
8285
----------

h2/events.py

+22
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,28 @@ def __repr__(self):
574574
)
575575

576576

577+
class UnknownFrameReceived(Event):
578+
"""
579+
The UnknownFrameReceived event is fired when the remote peer sends a frame
580+
that hyper-h2 does not understand. This occurs primarily when the remote
581+
peer is employing HTTP/2 extensions that hyper-h2 doesn't know anything
582+
about.
583+
584+
RFC 7540 requires that HTTP/2 implementations ignore these frames. hyper-h2
585+
does so. However, this event is fired to allow implementations to perform
586+
special processing on those frames if needed (e.g. if the implementation
587+
is capable of handling the frame itself).
588+
589+
.. versionadded:: 2.7.0
590+
"""
591+
def __init__(self):
592+
#: The hyperframe Frame object that encapsulates the received frame.
593+
self.frame = None
594+
595+
def __repr__(self):
596+
return "<UnknownFrameReceived>"
597+
598+
577599
def _bytes_representation(data):
578600
"""
579601
Converts a bytestring into something that is safe to print on all Python

test/test_events.py

+7
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,13 @@ def test_alternativeserviceavailable_repr(self):
323323
'field_value:h2=":8000"; ma=60>'
324324
)
325325

326+
def test_unknownframereceived_repr(self):
327+
"""
328+
UnknownFrameReceived has a useful debug representation.
329+
"""
330+
e = h2.events.UnknownFrameReceived()
331+
assert repr(e) == '<UnknownFrameReceived>'
332+
326333

327334
def all_events():
328335
"""

0 commit comments

Comments
 (0)