MCPcopy
hub / github.com/encode/starlette / test_websocket_headers

Function test_websocket_headers

tests/test_websockets.py:82–102  ·  view source on GitHub ↗
(test_client_factory: TestClientFactory)

Source from the content-addressed store, hash-verified

80 reason='urllib3 includes "br" to the "accept-encoding" headers.',
81)
82def test_websocket_headers(test_client_factory: TestClientFactory) -> None:
83 async def app(scope: Scope, receive: Receive, send: Send) -> None:
84 websocket = WebSocket(scope, receive=receive, send=send)
85 headers = dict(websocket.headers)
86 await websocket.accept()
87 await websocket.send_json({"headers": headers})
88 await websocket.close()
89
90 client = test_client_factory(app)
91 with client.websocket_connect("/") as websocket:
92 expected_headers = {
93 "accept": "*/*",
94 "accept-encoding": "gzip, deflate, zstd",
95 "connection": "upgrade",
96 "host": "testserver",
97 "user-agent": "testclient",
98 "sec-websocket-key": "testserver==",
99 "sec-websocket-version": "13",
100 }
101 data = websocket.receive_json()
102 assert data == {"headers": expected_headers}
103
104
105def test_websocket_port(test_client_factory: TestClientFactory) -> None:

Callers

nothing calls this directly

Calls 3

receive_jsonMethod · 0.95
test_client_factoryFunction · 0.85
websocket_connectMethod · 0.80

Tested by

no test coverage detected