@@ -374,11 +374,13 @@ def test_server_proxy_websocket_headers(
374
374
375
375
async def _websocket_subprotocols (a_server_port_and_token : Tuple [int , str ]) -> None :
376
376
PORT , TOKEN = a_server_port_and_token
377
- url = f"ws://{ LOCALHOST } :{ PORT } /python-websocket/subprotocolsocket "
377
+ url = f"ws://{ LOCALHOST } :{ PORT } /python-websocket/headerssocket "
378
378
conn = await websocket_connect (url , subprotocols = ["protocol_1" , "protocol_2" ])
379
379
await conn .write_message ("Hello, world!" )
380
380
msg = await conn .read_message ()
381
- assert json .loads (msg ) == ["protocol_1" , "protocol_2" ]
381
+ headers = json .loads (msg )
382
+ assert "Sec-Websocket-Protocol" in headers
383
+ assert headers ["Sec-Websocket-Protocol" ] == "protocol_1,protocol_2"
382
384
383
385
384
386
def test_server_proxy_websocket_subprotocols (
@@ -387,6 +389,39 @@ def test_server_proxy_websocket_subprotocols(
387
389
event_loop .run_until_complete (_websocket_subprotocols (a_server_port_and_token ))
388
390
389
391
392
+ async def _websocket_empty_subprotocols (a_server_port_and_token : Tuple [int , str ]) -> None :
393
+ PORT , TOKEN = a_server_port_and_token
394
+ url = f"ws://{ LOCALHOST } :{ PORT } /python-websocket/headerssocket"
395
+ conn = await websocket_connect (url , subprotocols = [])
396
+ await conn .write_message ("Hello, world!" )
397
+ msg = await conn .read_message ()
398
+ headers = json .loads (msg )
399
+ assert "Sec-Websocket-Protocol" in headers
400
+ assert headers ["Sec-Websocket-Protocol" ] == ""
401
+
402
+
403
+ def test_server_proxy_websocket_empty_subprotocols (
404
+ event_loop , a_server_port_and_token : Tuple [int , str ]
405
+ ):
406
+ event_loop .run_until_complete (_websocket_empty_subprotocols (a_server_port_and_token ))
407
+
408
+
409
+ async def _websocket_no_subprotocols (a_server_port_and_token : Tuple [int , str ]) -> None :
410
+ PORT , TOKEN = a_server_port_and_token
411
+ url = f"ws://{ LOCALHOST } :{ PORT } /python-websocket/headerssocket"
412
+ conn = await websocket_connect (url )
413
+ await conn .write_message ("Hello, world!" )
414
+ msg = await conn .read_message ()
415
+ headers = json .loads (msg )
416
+ assert "Sec-Websocket-Protocol" not in headers
417
+
418
+
419
+ def test_server_proxy_websocket_no_subprotocols (
420
+ event_loop , a_server_port_and_token : Tuple [int , str ]
421
+ ):
422
+ event_loop .run_until_complete (_websocket_no_subprotocols (a_server_port_and_token ))
423
+
424
+
390
425
@pytest .mark .parametrize (
391
426
"proxy_path, status" ,
392
427
[
0 commit comments