@@ -160,7 +160,7 @@ def test_returns_nothing(self, frame_factory):
160160 Calling initiate_upgrade_connection returns nothing.
161161 """
162162 conn = h2 .connection .H2Connection (client_side = False )
163- curl_header = "AAMAAABkAAQAAP__"
163+ curl_header = b "AAMAAABkAAQAAP__"
164164 data = conn .initiate_upgrade_connection (curl_header )
165165 assert data is None
166166
@@ -263,3 +263,42 @@ def test_cannot_receive_data_stream_1(self, frame_factory):
263263 error_code = h2 .errors .ErrorCodes .STREAM_CLOSED ,
264264 )
265265 assert c .data_to_send () == expected_frame .serialize ()
266+
267+ def test_client_settings_are_applied (self , frame_factory ):
268+ """
269+ The settings provided by the client are applied and immediately
270+ ACK'ed.
271+ """
272+ server = h2 .connection .H2Connection (client_side = False )
273+ client = h2 .connection .H2Connection (client_side = True )
274+
275+ # As a precaution, let's confirm that the server and client, at the
276+ # start of the connection, do not agree on their initial settings
277+ # state.
278+ assert (
279+ client .local_settings ._settings != server .remote_settings ._settings
280+ )
281+
282+ # Get the client header data and pass it to the server.
283+ header_data = client .initiate_upgrade_connection ()
284+ server .initiate_upgrade_connection (header_data )
285+
286+ # This gets complex, but here we go.
287+ # RFC 7540 § 3.2.1 says that "explicit acknowledgement" of the settings
288+ # in the header is "not necessary". That's annoyingly vague, but we
289+ # interpret that to mean "should not be sent". So to test that this
290+ # worked we need to test that the server has only sent the preamble,
291+ # and has not sent a SETTINGS ack, and also that the server has the
292+ # correct settings.
293+ expected_frame = frame_factory .build_settings_frame (
294+ server .local_settings
295+ )
296+ assert server .data_to_send () == expected_frame .serialize ()
297+
298+ # We violate abstraction layers here, but I don't think defining __eq__
299+ # for this is worth it. In this case, both the client and server should
300+ # agree that these settings have been ACK'd, so their underlying
301+ # dictionaries should be identical.
302+ assert (
303+ client .local_settings ._settings == server .remote_settings ._settings
304+ )
0 commit comments