Skip to content

Commit f323918

Browse files
committed
Update asyncio server example to pass h2spec tests
This requires two fixes, the first is to update the window when a settings frame is received that changes the initial window size (this frame can be received at any time). The second is to block whenever the flow control window is < 1 rather than != 0. This is important as clients can insist on a negative size window.
1 parent ede49d0 commit f323918

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

examples/asyncio/asyncio-server.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
from h2.config import H2Configuration
2020
from h2.connection import H2Connection
2121
from h2.events import (
22-
ConnectionTerminated, DataReceived, RequestReceived, StreamEnded,
23-
StreamReset, WindowUpdated
22+
ConnectionTerminated, DataReceived, RemoteSettingsChanged,
23+
RequestReceived, StreamEnded, StreamReset, WindowUpdated
2424
)
2525
from h2.errors import ErrorCodes
2626
from h2.exceptions import ProtocolError, StreamClosedError
27+
from h2.settings import SettingCodes
2728

2829

2930
RequestData = collections.namedtuple('RequestData', ['headers', 'data'])
@@ -68,6 +69,9 @@ def data_received(self, data: bytes):
6869
self.stream_reset(event.stream_id)
6970
elif isinstance(event, WindowUpdated):
7071
self.window_updated(event.stream_id, event.delta)
72+
elif isinstance(event, RemoteSettingsChanged):
73+
if SettingCodes.INITIAL_WINDOW_SIZE in event.changed_settings:
74+
self.window_updated(None, 0)
7175

7276
self.transport.write(self.conn.data_to_send())
7377

@@ -132,7 +136,7 @@ async def send_data(self, data, stream_id):
132136
Send data according to the flow control rules.
133137
"""
134138
while data:
135-
while not self.conn.local_flow_control_window(stream_id):
139+
while self.conn.local_flow_control_window(stream_id) < 1:
136140
try:
137141
await self.wait_for_flow_control(stream_id)
138142
except asyncio.CancelledError:

0 commit comments

Comments
 (0)