Skip to content
Myr

Remove ENABLE_CONNECT_PROTOCOL from HTTP/2 Settings (#373)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Seth Michael Larson · committed by GitHub · parent e1da6b9 · Browse files · 3 files+65 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+65 added−1 removed

  • tests:+42 added−0 removed
  • other:+23 added−1 removed

3 files+65 added−1 removed

modified:httpx/dispatch/http2.py+23 added-1 removed
1 unmodified line
2import typing34import h2.connection5import h2.events6from h2.settings import SettingCodes, Settings78from ..concurrency.base import BaseEvent, BaseTCPStream, ConcurrencyBackend, TimeoutFlag9from ..config import TimeoutConfig, TimeoutTypes10from ..exceptions import ProtocolError
54 unmodified lines
65 async def close(self) -> None:66 await self.stream.close()6768 def initiate_connection(self) -> None:69 # Need to set these manually here instead of manipulating via70 # __setitem__() otherwise the H2Connection will emit SettingsUpdate71 # frames in addition to sending the undesired defaults.72 self.h2_state.local_settings = Settings(73 client=True,74 initial_values={75 # Disable PUSH_PROMISE frames from the server since we don't do anything76 # with them for now. Maybe when we support caching?77 SettingCodes.ENABLE_PUSH: 0,78 # These two are taken from h2 for safe defaults79 SettingCodes.MAX_CONCURRENT_STREAMS: 100,80 SettingCodes.MAX_HEADER_LIST_SIZE: 65536,81 },82 )8384 # Some websites (*cough* Yahoo *cough*) balk at this setting being85 # present in the initial handshake since it's not defined in the original86 # RFC despite the RFC mandating ignoring settings you don't know about.87 del self.h2_state.local_settings[88 h2.settings.SettingCodes.ENABLE_CONNECT_PROTOCOL89 ]9091 self.h2_state.initiate_connection()92 data_to_send = self.h2_state.data_to_send()93 self.stream.write_no_block(data_to_send)94 self.initialized = True
15 unmodified lines
110 f"method={request.method!r} "111 f"target={request.url.full_path!r} "112 f"headers={headers!r}"113 )91114 self.h2_state.send_headers(stream_id, headers)115 data_to_send = self.h2_state.data_to_send()116 await self.stream.write(data_to_send, timeout)117 return stream_id
134 unmodified lines
modified:tests/dispatch/test_http2.py+39 added
1import json23import h2.connection4import h2.events5from h2.settings import SettingCodes67from httpx import AsyncClient, Client, Response89from .utils import MockHTTP2Backend10
157 unmodified lines
168 assert json.loads(response_1.content) == {"method": "GET", "path": "/1", "body": ""}169170 assert response_2.status_code == 200171 assert json.loads(response_2.content) == {"method": "GET", "path": "/2", "body": ""}172173174async def test_http2_settings_in_handshake(backend):175 backend = MockHTTP2Backend(app=app, backend=backend)176177 async with AsyncClient(backend=backend) as client:178 await client.get("http://example.org")179180 h2_conn = backend.server.conn181182 assert isinstance(h2_conn, h2.connection.H2Connection)183 expected_settings = {184 SettingCodes.HEADER_TABLE_SIZE: 4096,185 SettingCodes.ENABLE_PUSH: 0,186 SettingCodes.MAX_CONCURRENT_STREAMS: 100,187 SettingCodes.INITIAL_WINDOW_SIZE: 65535,188 SettingCodes.MAX_FRAME_SIZE: 16384,189 SettingCodes.MAX_HEADER_LIST_SIZE: 65536,190 # This one's here because h2 helpfully populates remote_settings191 # with default values even if the peer doesn't send the setting.192 SettingCodes.ENABLE_CONNECT_PROTOCOL: 0,193 }194 assert dict(h2_conn.remote_settings) == expected_settings195196 # We don't expect the ENABLE_CONNECT_PROTOCOL to be in the handshake197 expected_settings.pop(SettingCodes.ENABLE_CONNECT_PROTOCOL)198199 assert len(backend.server.settings_changed) == 1200 settings = backend.server.settings_changed[0]201202 assert isinstance(settings, h2.events.RemoteSettingsChanged)203 assert len(settings.changed_settings) == len(expected_settings)204 for setting_code, changed_setting in settings.changed_settings.items():205 assert isinstance(changed_setting, h2.settings.ChangedSetting)206 assert changed_setting.new_value == expected_settings[setting_code]
modified:tests/dispatch/utils.py+3 added
39 unmodified lines
40 self.requests = {}41 self.close_connection = False42 self.return_data = {}43 self.returning = {}44 self.settings_changed = []4546 # TCP stream interface4748 def get_http_version(self) -> str:
32 unmodified lines
81 self.send_return_data(key)82 # This will throw an error if the event is for a not-yet created stream83 elif self.returning[event.stream_id]:84 self.send_return_data(event.stream_id)85 elif isinstance(event, h2.events.RemoteSettingsChanged):86 self.settings_changed.append(event)8788 async def write(self, data: bytes, timeout) -> None:89 self.write_no_block(data)90
136 unmodified lines