galtimur's picture
Upload 78 files
11c83cb verified
raw
history blame
No virus
197 kB
{"language": "Python", "id": 43, "repo_owner": "encode", "repo_name": "uvicorn", "head_branch": "ioerror-on-send", "workflow_name": "Test Suite", "workflow_filename": "test-suite.yml", "workflow_path": ".github/workflows/test-suite.yml", "contributor": "encode", "sha_fail": "0b93d2da3b721c80dcb6a2993a23876a97498dd5", "sha_success": "bf13088dd7d7eb531cfbc02ee907f76103c4fa7a", "workflow": "---\nname: Test Suite\n\non:\n push:\n branches: [\"master\"]\n pull_request:\n branches: [\"master\"]\n\njobs:\n tests:\n name: \"Python ${{ matrix.python-version }} ${{ matrix.os }}\"\n runs-on: \"${{ matrix.os }}\"\n strategy:\n matrix:\n python-version: [\"3.8\", \"3.9\", \"3.10\", \"3.11\", \"3.12\"]\n os: [windows-latest, ubuntu-latest, macos-latest]\n steps:\n - uses: \"actions/checkout@v4\"\n - uses: \"actions/setup-python@v5\"\n with:\n python-version: \"${{ matrix.python-version }}\"\n - name: \"Install dependencies\"\n run: \"scripts/install\"\n shell: bash\n - name: \"Run linting checks\"\n run: \"scripts/check\"\n shell: bash\n if: \"${{ matrix.os == 'ubuntu-latest'}}\"\n - name: \"Build package & docs\"\n run: \"scripts/build\"\n shell: bash\n - name: \"Run tests\"\n run: \"scripts/test\"\n shell: bash\n - name: \"Enforce coverage\"\n run: \"scripts/coverage\"\n shell: bash\n", "logs": [{"step_name": "Python 3.9 ubuntu-latest/7_Run tests.txt", "log": "##[group]Run scripts/test\n\u001b[36;1mscripts/test\u001b[0m\nshell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}\nenv:\n pythonLocation: /opt/hostedtoolcache/Python/3.9.18/x64\n PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.9.18/x64/lib/pkgconfig\n Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.18/x64\n Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.18/x64\n Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.18/x64\n LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.9.18/x64/lib\n##[endgroup]\n+ [ -z true ]\n+ coverage run --debug config -m pytest\n-- config ----------------------------------------------------\n attempted_config_files: .coveragerc\n setup.cfg\n tox.ini\n pyproject.toml\n branch: False\n command_line: None\n concurrency: -none-\n config_file: /home/runner/work/uvicorn/uvicorn/pyproject.toml\n config_files_read: /home/runner/work/uvicorn/uvicorn/pyproject.toml\n context: None\n cover_pylib: False\n data_file: .coverage\n debug: config\n debug_file: None\n disable_warnings: -none-\n dynamic_context: None\n exclude_also: -none-\n exclude_list: pragma: no cover\n pragma: nocover\n if TYPE_CHECKING:\n if typing.TYPE_CHECKING:\n raise NotImplementedError\n py-not-win32\n py-linux\n py-gte-38\n py-gte-39\n py-lt-310\n py-lt-311\n extra_css: None\n fail_under: 98.35\n format: None\n html_dir: htmlcov\n html_skip_covered: None\n html_skip_empty: None\n html_title: Coverage report\n ignore_errors: False\n include_namespace_packages: False\n json_output: coverage.json\n json_pretty_print: False\n json_show_contexts: False\n lcov_output: coverage.lcov\n parallel: False\n partial_always_list: while (True|1|False|0):\n if (True|1|False|0):\n partial_list: #\\s*(pragma|PRAGMA)[:\\s]?\\s*(no|NO)\\s*(branch|BRANCH)\n paths: {}\n plugin_options: {'coverage_conditional_plugin': {'omit': {\"sys_platform == 'win32'\": ['uvicorn/loops/uvloop.py'], \"sys_platform != 'win32'\": ['uvicorn/loops/asyncio.py']}, 'rules': {'py-win32': \"sys_platform == 'win32'\", 'py-not-win32': \"sys_platform != 'win32'\", 'py-linux': \"sys_platform == 'linux'\", 'py-darwin': \"sys_platform == 'darwin'\", 'py-gte-38': 'sys_version_info >= (3, 8)', 'py-lt-38': 'sys_version_info < (3, 8)', 'py-gte-39': 'sys_version_info >= (3, 9)', 'py-lt-39': 'sys_version_info < (3, 9)', 'py-gte-310': 'sys_version_info >= (3, 10)', 'py-lt-310': 'sys_version_info < (3, 10)', 'py-gte-311': 'sys_version_info >= (3, 11)', 'py-lt-311': 'sys_version_info < (3, 11)'}}}\n plugins: coverage_conditional_plugin\n precision: 2\n relative_files: False\n report_contexts: None\n report_include: None\n report_omit: None\n run_include: -none-\n run_omit: uvicorn/workers.py\n uvicorn/__main__.py\n uvicorn/loops/asyncio.py\n show_contexts: False\n show_missing: True\n sigterm: False\n skip_covered: True\n skip_empty: False\n sort: None\n source: None\n source_pkgs: uvicorn\n tests\n timid: False\n xml_output: coverage.xml\n xml_package_depth: 99\n-- end -------------------------------------------------------\n============================= test session starts ==============================\nplatform linux -- Python 3.9.18, pytest-7.4.4, pluggy-1.3.0\nrootdir: /home/runner/work/uvicorn/uvicorn\nconfigfile: pyproject.toml\nplugins: anyio-3.7.1, mock-3.12.0\ncollected 565 items\n\ntests/test_auto_detection.py ... [ 0%]\ntests/test_cli.py .............. [ 3%]\ntests/test_config.py ................................................... [ 12%]\n........................................................ [ 21%]\ntests/test_default_headers.py ...... [ 23%]\ntests/test_lifespan.py ................ [ 25%]\ntests/test_main.py ......... [ 27%]\ntests/test_ssl.py .... [ 28%]\ntests/test_subprocess.py .. [ 28%]\ntests/importer/test_importer.py ....... [ 29%]\ntests/middleware/test_logging.py .............. [ 32%]\ntests/middleware/test_message_logger.py .. [ 32%]\ntests/middleware/test_proxy_headers.py ............... [ 35%]\ntests/middleware/test_wsgi.py ........... [ 37%]\ntests/protocols/test_http.py ........................................... [ 44%]\n............................................................... [ 55%]\ntests/protocols/test_utils.py ...... [ 56%]\ntests/protocols/test_websocket.py ...................................... [ 63%]\n........................................................................ [ 76%]\n........................................................FF......FF..FF.. [ 89%]\n.................... [ 92%]\ntests/supervisors/test_multiprocess.py . [ 92%]\ntests/supervisors/test_reload.py ..................................... [ 99%]\ntests/supervisors/test_signal.py ... [100%]\n\n=================================== FAILURES ===================================\n____ test_server_reject_connection_with_body_nolength[websockets-httptools] ____\n\n @contextlib.contextmanager\n def map_httpcore_exceptions() -> typing.Iterator[None]:\n try:\n> yield\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpx/_transports/default.py:67: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpx/_transports/default.py:371: in handle_async_request\n resp = await self._pool.handle_async_request(req)\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpcore/_async/connection_pool.py:268: in handle_async_request\n raise exc\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpcore/_async/connection_pool.py:251: in handle_async_request\n response = await connection.handle_async_request(request)\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpcore/_async/connection.py:103: in handle_async_request\n return await self._connection.handle_async_request(request)\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpcore/_async/http11.py:133: in handle_async_request\n raise exc\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpcore/_async/http11.py:111: in handle_async_request\n ) = await self._receive_response_headers(**kwargs)\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpcore/_async/http11.py:176: in _receive_response_headers\n event = await self._receive_event(timeout=timeout)\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <AsyncHTTP11Connection ['http://127.0.0.1:60493', CLOSED, Request Count: 1]>\ntimeout = 5.0\n\n async def _receive_event(\n self, timeout: Optional[float] = None\n ) -> Union[h11.Event, Type[h11.PAUSED]]:\n while True:\n with map_exceptions({h11.RemoteProtocolError: RemoteProtocolError}):\n event = self._h11_state.next_event()\n \n if event is h11.NEED_DATA:\n data = await self._network_stream.read(\n self.READ_NUM_BYTES, timeout=timeout\n )\n \n # If we feed this case through h11 we'll raise an exception like:\n #\n # httpcore.RemoteProtocolError: can't handle event type\n # ConnectionClosed when role=SERVER and state=SEND_RESPONSE\n #\n # Which is accurate, but not very informative from an end-user\n # perspective. Instead we handle this case distinctly and treat\n # it as a ConnectError.\n if data == b\"\" and self._h11_state.their_state == h11.SEND_RESPONSE:\n msg = \"Server disconnected without sending a response.\"\n> raise RemoteProtocolError(msg)\nE httpcore.RemoteProtocolError: Server disconnected without sending a response.\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpcore/_async/http11.py:226: RemoteProtocolError\n\nThe above exception was the direct cause of the following exception:\n\nws_protocol_cls = <class 'uvicorn.protocols.websockets.websockets_impl.WebSocketProtocol'>\nhttp_protocol_cls = <class 'uvicorn.protocols.http.httptools_impl.HttpToolsProtocol'>\nunused_tcp_port = 60493\n\n @pytest.mark.anyio\n async def test_server_reject_connection_with_body_nolength(\n ws_protocol_cls: \"typing.Type[WSProtocol | WebSocketProtocol]\",\n http_protocol_cls: \"typing.Type[H11Protocol | HttpToolsProtocol]\",\n unused_tcp_port: int,\n ):\n # test that the server can send a response with a body but no content-length\n async def app(scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable):\n assert scope[\"type\"] == \"websocket\"\n assert \"extensions\" in scope\n assert \"websocket.http.response\" in scope[\"extensions\"]\n \n # Pull up first recv message.\n message = await receive()\n assert message[\"type\"] == \"websocket.connect\"\n \n await send(\n {\n \"type\": \"websocket.http.response.start\",\n \"status\": 403,\n \"headers\": [],\n }\n )\n await send({\"type\": \"websocket.http.response.body\", \"body\": b\"hardbody\"})\n \n async def websocket_session(url):\n response = await wsresponse(url)\n assert response.status_code == 403\n assert response.content == b\"hardbody\"\n if ws_protocol_cls == WSProtocol: # pragma: no cover\n # wsproto automatically makes the message chunked\n assert response.headers[\"transfer-encoding\"] == \"chunked\"\n else: # pragma: no cover\n # websockets automatically adds a content-length\n assert response.headers[\"content-length\"] == \"8\"\n \n config = Config(\n app=app,\n ws=ws_protocol_cls,\n http=http_protocol_cls,\n lifespan=\"off\",\n port=unused_tcp_port,\n )\n async with run_server(config):\n> await websocket_session(f\"ws://127.0.0.1:{unused_tcp_port}\")\n\ntests/protocols/test_websocket.py:1219: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ntests/protocols/test_websocket.py:1201: in websocket_session\n response = await wsresponse(url)\ntests/protocols/test_websocket.py:73: in wsresponse\n return await client.get(url, headers=headers)\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpx/_client.py:1786: in get\n return await self.request(\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpx/_client.py:1559: in request\n return await self.send(request, auth=auth, follow_redirects=follow_redirects)\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpx/_client.py:1646: in send\n response = await self._send_handling_auth(\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpx/_client.py:1674: in _send_handling_auth\n response = await self._send_handling_redirects(\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpx/_client.py:1711: in _send_handling_redirects\n response = await self._send_single_request(request)\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpx/_client.py:1748: in _send_single_request\n response = await transport.handle_async_request(request)\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpx/_transports/default.py:371: in handle_async_request\n resp = await self._pool.handle_async_request(req)\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/contextlib.py:137: in __exit__\n self.gen.throw(typ, value, traceback)\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n @contextlib.contextmanager\n def map_httpcore_exceptions() -> typing.Iterator[None]:\n try:\n yield\n except Exception as exc:\n mapped_exc = None\n \n for from_exc, to_exc in HTTPCORE_EXC_MAP.items():\n if not isinstance(exc, from_exc):\n continue\n # We want to map to the most specific exception we can find.\n # Eg if `exc` is an `httpcore.ReadTimeout`, we want to map to\n # `httpx.ReadTimeout`, not just `httpx.TimeoutException`.\n if mapped_exc is None or issubclass(to_exc, mapped_exc):\n mapped_exc = to_exc\n \n if mapped_exc is None: # pragma: no cover\n raise\n \n message = str(exc)\n> raise mapped_exc(message) from exc\nE httpx.RemoteProtocolError: Server disconnected without sending a response.\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpx/_transports/default.py:84: RemoteProtocolError\n----------------------------- Captured stderr call -----------------------------\nINFO: Started server process [1904]\nINFO: Uvicorn running on http://127.0.0.1:60493 (Press CTRL+C to quit)\nINFO: ('127.0.0.1', 57402) - \"WebSocket /\" 403\nINFO: connection rejected (403 Forbidden)\nINFO: connection closed\nINFO: Shutting down\n------------------------------ Captured log call -------------------------------\nINFO uvicorn.error:server.py:77 Started server process [1904]\nINFO uvicorn.error:server.py:219 Uvicorn running on http://127.0.0.1:60493 (Press CTRL+C to quit)\nINFO uvicorn.error:websockets_impl.py:317 ('127.0.0.1', 57402) - \"WebSocket /\" 403\nINFO uvicorn.error:server.py:229 connection rejected (403 Forbidden)\nINFO uvicorn.error:server.py:264 connection closed\nINFO uvicorn.error:server.py:265 Shutting down\n_______ test_server_reject_connection_with_body_nolength[websockets-h11] _______\n\n @contextlib.contextmanager\n def map_httpcore_exceptions() -> typing.Iterator[None]:\n try:\n> yield\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpx/_transports/default.py:67: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpx/_transports/default.py:371: in handle_async_request\n resp = await self._pool.handle_async_request(req)\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpcore/_async/connection_pool.py:268: in handle_async_request\n raise exc\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpcore/_async/connection_pool.py:251: in handle_async_request\n response = await connection.handle_async_request(request)\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpcore/_async/connection.py:103: in handle_async_request\n return await self._connection.handle_async_request(request)\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpcore/_async/http11.py:133: in handle_async_request\n raise exc\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpcore/_async/http11.py:111: in handle_async_request\n ) = await self._receive_response_headers(**kwargs)\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpcore/_async/http11.py:176: in _receive_response_headers\n event = await self._receive_event(timeout=timeout)\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <AsyncHTTP11Connection ['http://127.0.0.1:54995', CLOSED, Request Count: 1]>\ntimeout = 5.0\n\n async def _receive_event(\n self, timeout: Optional[float] = None\n ) -> Union[h11.Event, Type[h11.PAUSED]]:\n while True:\n with map_exceptions({h11.RemoteProtocolError: RemoteProtocolError}):\n event = self._h11_state.next_event()\n \n if event is h11.NEED_DATA:\n data = await self._network_stream.read(\n self.READ_NUM_BYTES, timeout=timeout\n )\n \n # If we feed this case through h11 we'll raise an exception like:\n #\n # httpcore.RemoteProtocolError: can't handle event type\n # ConnectionClosed when role=SERVER and state=SEND_RESPONSE\n #\n # Which is accurate, but not very informative from an end-user\n # perspective. Instead we handle this case distinctly and treat\n # it as a ConnectError.\n if data == b\"\" and self._h11_state.their_state == h11.SEND_RESPONSE:\n msg = \"Server disconnected without sending a response.\"\n> raise RemoteProtocolError(msg)\nE httpcore.RemoteProtocolError: Server disconnected without sending a response.\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpcore/_async/http11.py:226: RemoteProtocolError\n\nThe above exception was the direct cause of the following exception:\n\nws_protocol_cls = <class 'uvicorn.protocols.websockets.websockets_impl.WebSocketProtocol'>\nhttp_protocol_cls = <class 'uvicorn.protocols.http.h11_impl.H11Protocol'>\nunused_tcp_port = 54995\n\n @pytest.mark.anyio\n async def test_server_reject_connection_with_body_nolength(\n ws_protocol_cls: \"typing.Type[WSProtocol | WebSocketProtocol]\",\n http_protocol_cls: \"typing.Type[H11Protocol | HttpToolsProtocol]\",\n unused_tcp_port: int,\n ):\n # test that the server can send a response with a body but no content-length\n async def app(scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable):\n assert scope[\"type\"] == \"websocket\"\n assert \"extensions\" in scope\n assert \"websocket.http.response\" in scope[\"extensions\"]\n \n # Pull up first recv message.\n message = await receive()\n assert message[\"type\"] == \"websocket.connect\"\n \n await send(\n {\n \"type\": \"websocket.http.response.start\",\n \"status\": 403,\n \"headers\": [],\n }\n )\n await send({\"type\": \"websocket.http.response.body\", \"body\": b\"hardbody\"})\n \n async def websocket_session(url):\n response = await wsresponse(url)\n assert response.status_code == 403\n assert response.content == b\"hardbody\"\n if ws_protocol_cls == WSProtocol: # pragma: no cover\n # wsproto automatically makes the message chunked\n assert response.headers[\"transfer-encoding\"] == \"chunked\"\n else: # pragma: no cover\n # websockets automatically adds a content-length\n assert response.headers[\"content-length\"] == \"8\"\n \n config = Config(\n app=app,\n ws=ws_protocol_cls,\n http=http_protocol_cls,\n lifespan=\"off\",\n port=unused_tcp_port,\n )\n async with run_server(config):\n> await websocket_session(f\"ws://127.0.0.1:{unused_tcp_port}\")\n\ntests/protocols/test_websocket.py:1219: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ntests/protocols/test_websocket.py:1201: in websocket_session\n response = await wsresponse(url)\ntests/protocols/test_websocket.py:73: in wsresponse\n return await client.get(url, headers=headers)\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpx/_client.py:1786: in get\n return await self.request(\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpx/_client.py:1559: in request\n return await self.send(request, auth=auth, follow_redirects=follow_redirects)\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpx/_client.py:1646: in send\n response = await self._send_handling_auth(\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpx/_client.py:1674: in _send_handling_auth\n response = await self._send_handling_redirects(\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpx/_client.py:1711: in _send_handling_redirects\n response = await self._send_single_request(request)\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpx/_client.py:1748: in _send_single_request\n response = await transport.handle_async_request(request)\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpx/_transports/default.py:371: in handle_async_request\n resp = await self._pool.handle_async_request(req)\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/contextlib.py:137: in __exit__\n self.gen.throw(typ, value, traceback)\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n @contextlib.contextmanager\n def map_httpcore_exceptions() -> typing.Iterator[None]:\n try:\n yield\n except Exception as exc:\n mapped_exc = None\n \n for from_exc, to_exc in HTTPCORE_EXC_MAP.items():\n if not isinstance(exc, from_exc):\n continue\n # We want to map to the most specific exception we can find.\n # Eg if `exc` is an `httpcore.ReadTimeout`, we want to map to\n # `httpx.ReadTimeout`, not just `httpx.TimeoutException`.\n if mapped_exc is None or issubclass(to_exc, mapped_exc):\n mapped_exc = to_exc\n \n if mapped_exc is None: # pragma: no cover\n raise\n \n message = str(exc)\n> raise mapped_exc(message) from exc\nE httpx.RemoteProtocolError: Server disconnected without sending a response.\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/httpx/_transports/default.py:84: RemoteProtocolError\n----------------------------- Captured stderr call -----------------------------\nINFO: Started server process [1904]\nINFO: Uvicorn running on http://127.0.0.1:54995 (Press CTRL+C to quit)\nINFO: ('127.0.0.1', 45664) - \"WebSocket /\" 403\nINFO: connection rejected (403 Forbidden)\nINFO: connection closed\nINFO: Shutting down\n------------------------------ Captured log call -------------------------------\nINFO uvicorn.error:server.py:77 Started server process [1904]\nINFO uvicorn.error:server.py:219 Uvicorn running on http://127.0.0.1:54995 (Press CTRL+C to quit)\nINFO uvicorn.error:websockets_impl.py:317 ('127.0.0.1', 45664) - \"WebSocket /\" 403\nINFO uvicorn.error:server.py:229 connection rejected (403 Forbidden)\nINFO uvicorn.error:server.py:264 connection closed\nINFO uvicorn.error:server.py:265 Shutting down\n____ test_server_reject_connection_with_missing_body[websockets-httptools] _____\n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x55cef4c70630>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n> status_line = await read_line(stream)\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/http.py:120: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x55cef4c70630>>\n\n async def read_line(stream: asyncio.StreamReader) -> bytes:\n \"\"\"\n Read a single line from ``stream``.\n \n CRLF is stripped from the return value.\n \n \"\"\"\n # Security: this is bounded by the StreamReader's limit (default = 32\u00a0KiB).\n line = await stream.readline()\n # Security: this guarantees header values are small (hard-coded = 8\u00a0KiB)\n if len(line) > MAX_LINE:\n raise SecurityError(\"line too long\")\n # Not mandatory but safe - https://www.rfc-editor.org/rfc/rfc7230.html#section-3.5\n if not line.endswith(b\"\\r\\n\"):\n> raise EOFError(\"line without CRLF\")\nE EOFError: line without CRLF\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/http.py:200: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7fb3f5aa1d90>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n> status_code, reason, headers = await read_response(self.reader)\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:139: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x55cef4c70630>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n status_line = await read_line(stream)\n except EOFError as exc:\n> raise EOFError(\"connection closed while reading HTTP status line\") from exc\nE EOFError: connection closed while reading HTTP status line\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/http.py:122: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nws_protocol_cls = <class 'uvicorn.protocols.websockets.websockets_impl.WebSocketProtocol'>\nhttp_protocol_cls = <class 'uvicorn.protocols.http.httptools_impl.HttpToolsProtocol'>\nunused_tcp_port = 60941\n\n @pytest.mark.anyio\n async def test_server_reject_connection_with_missing_body(\n ws_protocol_cls: \"typing.Type[WSProtocol | WebSocketProtocol]\",\n http_protocol_cls: \"typing.Type[H11Protocol | HttpToolsProtocol]\",\n unused_tcp_port: int,\n ):\n async def app(scope, receive, send):\n assert scope[\"type\"] == \"websocket\"\n assert \"websocket.http.response\" in scope[\"extensions\"]\n \n # Pull up first recv message.\n message = await receive()\n assert message[\"type\"] == \"websocket.connect\"\n \n message = {\n \"type\": \"websocket.http.response.start\",\n \"status\": 404,\n \"headers\": [(b\"Content-Length\", b\"0\"), (b\"Content-Type\", b\"text/plain\")],\n }\n await send(message)\n # no further message\n \n async def websocket_session(url):\n with pytest.raises(websockets.exceptions.InvalidStatusCode) as exc_info:\n async with websockets.client.connect(url):\n pass # pragma: no cover\n assert exc_info.value.status_code == 404\n \n config = Config(\n app=app,\n ws=ws_protocol_cls,\n http=http_protocol_cls,\n lifespan=\"off\",\n port=unused_tcp_port,\n )\n async with run_server(config):\n> await websocket_session(f\"ws://127.0.0.1:{unused_tcp_port}\")\n\ntests/protocols/test_websocket.py:1298: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ntests/protocols/test_websocket.py:1286: in websocket_session\n async with websockets.client.connect(url):\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:629: in __aenter__\n return await self\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:647: in __await_impl_timeout__\n return await self.__await_impl__()\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:654: in __await_impl__\n await protocol.handshake(\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:319: in handshake\n status_code, response_headers = await self.read_http_response()\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7fb3f5aa1d90>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n status_code, reason, headers = await read_response(self.reader)\n except Exception as exc:\n> raise InvalidMessage(\"did not receive a valid HTTP response\") from exc\nE websockets.exceptions.InvalidMessage: did not receive a valid HTTP response\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:141: InvalidMessage\n----------------------------- Captured stderr call -----------------------------\nINFO: Started server process [1904]\nINFO: Uvicorn running on http://127.0.0.1:60941 (Press CTRL+C to quit)\nINFO: ('127.0.0.1', 60230) - \"WebSocket /\" 404\nINFO: connection rejected (404 Not Found)\nINFO: connection closed\nINFO: Shutting down\n------------------------------ Captured log call -------------------------------\nINFO uvicorn.error:server.py:77 Started server process [1904]\nINFO uvicorn.error:server.py:219 Uvicorn running on http://127.0.0.1:60941 (Press CTRL+C to quit)\nINFO uvicorn.error:websockets_impl.py:317 ('127.0.0.1', 60230) - \"WebSocket /\" 404\nINFO uvicorn.error:server.py:229 connection rejected (404 Not Found)\nINFO uvicorn.error:server.py:264 connection closed\nINFO uvicorn.error:server.py:265 Shutting down\n_______ test_server_reject_connection_with_missing_body[websockets-h11] ________\n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x55cef4c70380>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n> status_line = await read_line(stream)\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/http.py:120: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x55cef4c70380>>\n\n async def read_line(stream: asyncio.StreamReader) -> bytes:\n \"\"\"\n Read a single line from ``stream``.\n \n CRLF is stripped from the return value.\n \n \"\"\"\n # Security: this is bounded by the StreamReader's limit (default = 32\u00a0KiB).\n line = await stream.readline()\n # Security: this guarantees header values are small (hard-coded = 8\u00a0KiB)\n if len(line) > MAX_LINE:\n raise SecurityError(\"line too long\")\n # Not mandatory but safe - https://www.rfc-editor.org/rfc/rfc7230.html#section-3.5\n if not line.endswith(b\"\\r\\n\"):\n> raise EOFError(\"line without CRLF\")\nE EOFError: line without CRLF\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/http.py:200: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7fb3f5fad130>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n> status_code, reason, headers = await read_response(self.reader)\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:139: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x55cef4c70380>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n status_line = await read_line(stream)\n except EOFError as exc:\n> raise EOFError(\"connection closed while reading HTTP status line\") from exc\nE EOFError: connection closed while reading HTTP status line\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/http.py:122: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nws_protocol_cls = <class 'uvicorn.protocols.websockets.websockets_impl.WebSocketProtocol'>\nhttp_protocol_cls = <class 'uvicorn.protocols.http.h11_impl.H11Protocol'>\nunused_tcp_port = 38791\n\n @pytest.mark.anyio\n async def test_server_reject_connection_with_missing_body(\n ws_protocol_cls: \"typing.Type[WSProtocol | WebSocketProtocol]\",\n http_protocol_cls: \"typing.Type[H11Protocol | HttpToolsProtocol]\",\n unused_tcp_port: int,\n ):\n async def app(scope, receive, send):\n assert scope[\"type\"] == \"websocket\"\n assert \"websocket.http.response\" in scope[\"extensions\"]\n \n # Pull up first recv message.\n message = await receive()\n assert message[\"type\"] == \"websocket.connect\"\n \n message = {\n \"type\": \"websocket.http.response.start\",\n \"status\": 404,\n \"headers\": [(b\"Content-Length\", b\"0\"), (b\"Content-Type\", b\"text/plain\")],\n }\n await send(message)\n # no further message\n \n async def websocket_session(url):\n with pytest.raises(websockets.exceptions.InvalidStatusCode) as exc_info:\n async with websockets.client.connect(url):\n pass # pragma: no cover\n assert exc_info.value.status_code == 404\n \n config = Config(\n app=app,\n ws=ws_protocol_cls,\n http=http_protocol_cls,\n lifespan=\"off\",\n port=unused_tcp_port,\n )\n async with run_server(config):\n> await websocket_session(f\"ws://127.0.0.1:{unused_tcp_port}\")\n\ntests/protocols/test_websocket.py:1298: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ntests/protocols/test_websocket.py:1286: in websocket_session\n async with websockets.client.connect(url):\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:629: in __aenter__\n return await self\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:647: in __await_impl_timeout__\n return await self.__await_impl__()\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:654: in __await_impl__\n await protocol.handshake(\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:319: in handshake\n status_code, response_headers = await self.read_http_response()\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7fb3f5fad130>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n status_code, reason, headers = await read_response(self.reader)\n except Exception as exc:\n> raise InvalidMessage(\"did not receive a valid HTTP response\") from exc\nE websockets.exceptions.InvalidMessage: did not receive a valid HTTP response\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:141: InvalidMessage\n----------------------------- Captured stderr call -----------------------------\nINFO: Started server process [1904]\nINFO: Uvicorn running on http://127.0.0.1:38791 (Press CTRL+C to quit)\nINFO: ('127.0.0.1', 50712) - \"WebSocket /\" 404\nINFO: connection rejected (404 Not Found)\nINFO: connection closed\nINFO: Shutting down\n------------------------------ Captured log call -------------------------------\nINFO uvicorn.error:server.py:77 Started server process [1904]\nINFO uvicorn.error:server.py:219 Uvicorn running on http://127.0.0.1:38791 (Press CTRL+C to quit)\nINFO uvicorn.error:websockets_impl.py:317 ('127.0.0.1', 50712) - \"WebSocket /\" 404\nINFO uvicorn.error:server.py:229 connection rejected (404 Not Found)\nINFO uvicorn.error:server.py:264 connection closed\nINFO uvicorn.error:server.py:265 Shutting down\n_ test_server_multiple_websocket_http_response_start_events[websockets-httptools] _\n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x55cef42e1800>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n> status_line = await read_line(stream)\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/http.py:120: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x55cef42e1800>>\n\n async def read_line(stream: asyncio.StreamReader) -> bytes:\n \"\"\"\n Read a single line from ``stream``.\n \n CRLF is stripped from the return value.\n \n \"\"\"\n # Security: this is bounded by the StreamReader's limit (default = 32\u00a0KiB).\n line = await stream.readline()\n # Security: this guarantees header values are small (hard-coded = 8\u00a0KiB)\n if len(line) > MAX_LINE:\n raise SecurityError(\"line too long\")\n # Not mandatory but safe - https://www.rfc-editor.org/rfc/rfc7230.html#section-3.5\n if not line.endswith(b\"\\r\\n\"):\n> raise EOFError(\"line without CRLF\")\nE EOFError: line without CRLF\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/http.py:200: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7fb3f80c9dc0>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n> status_code, reason, headers = await read_response(self.reader)\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:139: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x55cef42e1800>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n status_line = await read_line(stream)\n except EOFError as exc:\n> raise EOFError(\"connection closed while reading HTTP status line\") from exc\nE EOFError: connection closed while reading HTTP status line\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/http.py:122: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nws_protocol_cls = <class 'uvicorn.protocols.websockets.websockets_impl.WebSocketProtocol'>\nhttp_protocol_cls = <class 'uvicorn.protocols.http.httptools_impl.HttpToolsProtocol'>\nunused_tcp_port = 52319\n\n @pytest.mark.anyio\n async def test_server_multiple_websocket_http_response_start_events(\n ws_protocol_cls: \"typing.Type[WSProtocol | WebSocketProtocol]\",\n http_protocol_cls: \"typing.Type[H11Protocol | HttpToolsProtocol]\",\n unused_tcp_port: int,\n ):\n \"\"\"\n The server should raise an exception if it sends multiple\n websocket.http.response.start events.\n \"\"\"\n exception_message: typing.Optional[str] = None\n \n async def app(scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable):\n nonlocal exception_message\n assert scope[\"type\"] == \"websocket\"\n assert \"extensions\" in scope\n assert \"websocket.http.response\" in scope[\"extensions\"]\n \n # Pull up first recv message.\n message = await receive()\n assert message[\"type\"] == \"websocket.connect\"\n \n start_event: WebSocketResponseStartEvent = {\n \"type\": \"websocket.http.response.start\",\n \"status\": 404,\n \"headers\": [(b\"Content-Length\", b\"0\"), (b\"Content-Type\", b\"text/plain\")],\n }\n await send(start_event)\n try:\n await send(start_event)\n except Exception as exc:\n exception_message = str(exc)\n \n async def websocket_session(url: str):\n with pytest.raises(websockets.exceptions.InvalidStatusCode) as exc_info:\n async with websockets.client.connect(url):\n pass\n assert exc_info.value.status_code == 404\n \n config = Config(\n app=app,\n ws=ws_protocol_cls,\n http=http_protocol_cls,\n lifespan=\"off\",\n port=unused_tcp_port,\n )\n async with run_server(config):\n> await websocket_session(f\"ws://127.0.0.1:{unused_tcp_port}\")\n\ntests/protocols/test_websocket.py:1348: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ntests/protocols/test_websocket.py:1336: in websocket_session\n async with websockets.client.connect(url):\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:629: in __aenter__\n return await self\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:647: in __await_impl_timeout__\n return await self.__await_impl__()\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:654: in __await_impl__\n await protocol.handshake(\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:319: in handshake\n status_code, response_headers = await self.read_http_response()\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7fb3f80c9dc0>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n status_code, reason, headers = await read_response(self.reader)\n except Exception as exc:\n> raise InvalidMessage(\"did not receive a valid HTTP response\") from exc\nE websockets.exceptions.InvalidMessage: did not receive a valid HTTP response\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:141: InvalidMessage\n----------------------------- Captured stderr call -----------------------------\nINFO: Started server process [1904]\nINFO: Uvicorn running on http://127.0.0.1:52319 (Press CTRL+C to quit)\nINFO: ('127.0.0.1', 34168) - \"WebSocket /\" 404\nINFO: connection rejected (404 Not Found)\nINFO: connection closed\nINFO: Shutting down\n------------------------------ Captured log call -------------------------------\nINFO uvicorn.error:server.py:77 Started server process [1904]\nINFO uvicorn.error:server.py:219 Uvicorn running on http://127.0.0.1:52319 (Press CTRL+C to quit)\nINFO uvicorn.error:websockets_impl.py:317 ('127.0.0.1', 34168) - \"WebSocket /\" 404\nINFO uvicorn.error:server.py:229 connection rejected (404 Not Found)\nINFO uvicorn.error:server.py:264 connection closed\nINFO uvicorn.error:server.py:265 Shutting down\n__ test_server_multiple_websocket_http_response_start_events[websockets-h11] ___\n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x55cef457fbd0>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n> status_line = await read_line(stream)\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/http.py:120: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x55cef457fbd0>>\n\n async def read_line(stream: asyncio.StreamReader) -> bytes:\n \"\"\"\n Read a single line from ``stream``.\n \n CRLF is stripped from the return value.\n \n \"\"\"\n # Security: this is bounded by the StreamReader's limit (default = 32\u00a0KiB).\n line = await stream.readline()\n # Security: this guarantees header values are small (hard-coded = 8\u00a0KiB)\n if len(line) > MAX_LINE:\n raise SecurityError(\"line too long\")\n # Not mandatory but safe - https://www.rfc-editor.org/rfc/rfc7230.html#section-3.5\n if not line.endswith(b\"\\r\\n\"):\n> raise EOFError(\"line without CRLF\")\nE EOFError: line without CRLF\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/http.py:200: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7fb3f83c13a0>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n> status_code, reason, headers = await read_response(self.reader)\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:139: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x55cef457fbd0>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n status_line = await read_line(stream)\n except EOFError as exc:\n> raise EOFError(\"connection closed while reading HTTP status line\") from exc\nE EOFError: connection closed while reading HTTP status line\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/http.py:122: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nws_protocol_cls = <class 'uvicorn.protocols.websockets.websockets_impl.WebSocketProtocol'>\nhttp_protocol_cls = <class 'uvicorn.protocols.http.h11_impl.H11Protocol'>\nunused_tcp_port = 54615\n\n @pytest.mark.anyio\n async def test_server_multiple_websocket_http_response_start_events(\n ws_protocol_cls: \"typing.Type[WSProtocol | WebSocketProtocol]\",\n http_protocol_cls: \"typing.Type[H11Protocol | HttpToolsProtocol]\",\n unused_tcp_port: int,\n ):\n \"\"\"\n The server should raise an exception if it sends multiple\n websocket.http.response.start events.\n \"\"\"\n exception_message: typing.Optional[str] = None\n \n async def app(scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable):\n nonlocal exception_message\n assert scope[\"type\"] == \"websocket\"\n assert \"extensions\" in scope\n assert \"websocket.http.response\" in scope[\"extensions\"]\n \n # Pull up first recv message.\n message = await receive()\n assert message[\"type\"] == \"websocket.connect\"\n \n start_event: WebSocketResponseStartEvent = {\n \"type\": \"websocket.http.response.start\",\n \"status\": 404,\n \"headers\": [(b\"Content-Length\", b\"0\"), (b\"Content-Type\", b\"text/plain\")],\n }\n await send(start_event)\n try:\n await send(start_event)\n except Exception as exc:\n exception_message = str(exc)\n \n async def websocket_session(url: str):\n with pytest.raises(websockets.exceptions.InvalidStatusCode) as exc_info:\n async with websockets.client.connect(url):\n pass\n assert exc_info.value.status_code == 404\n \n config = Config(\n app=app,\n ws=ws_protocol_cls,\n http=http_protocol_cls,\n lifespan=\"off\",\n port=unused_tcp_port,\n )\n async with run_server(config):\n> await websocket_session(f\"ws://127.0.0.1:{unused_tcp_port}\")\n\ntests/protocols/test_websocket.py:1348: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ntests/protocols/test_websocket.py:1336: in websocket_session\n async with websockets.client.connect(url):\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:629: in __aenter__\n return await self\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:647: in __await_impl_timeout__\n return await self.__await_impl__()\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:654: in __await_impl__\n await protocol.handshake(\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:319: in handshake\n status_code, response_headers = await self.read_http_response()\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7fb3f83c13a0>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n status_code, reason, headers = await read_response(self.reader)\n except Exception as exc:\n> raise InvalidMessage(\"did not receive a valid HTTP response\") from exc\nE websockets.exceptions.InvalidMessage: did not receive a valid HTTP response\n\n/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/websockets/legacy/client.py:141: InvalidMessage\n----------------------------- Captured stderr call -----------------------------\nINFO: Started server process [1904]\nINFO: Uvicorn running on http://127.0.0.1:54615 (Press CTRL+C to quit)\nINFO: ('127.0.0.1', 48684) - \"WebSocket /\" 404\nINFO: connection rejected (404 Not Found)\nINFO: connection closed\nINFO: Shutting down\n------------------------------ Captured log call -------------------------------\nINFO uvicorn.error:server.py:77 Started server process [1904]\nINFO uvicorn.error:server.py:219 Uvicorn running on http://127.0.0.1:54615 (Press CTRL+C to quit)\nINFO uvicorn.error:websockets_impl.py:317 ('127.0.0.1', 48684) - \"WebSocket /\" 404\nINFO uvicorn.error:server.py:229 connection rejected (404 Not Found)\nINFO uvicorn.error:server.py:264 connection closed\nINFO uvicorn.error:server.py:265 Shutting down\n=================== 6 failed, 559 passed in 66.02s (0:01:06) ===================\n##[error]Process completed with exit code 1.\n"}, {"step_name": "Python 3.10 ubuntu-latest/7_Run tests.txt", "log": "##[group]Run scripts/test\n\u001b[36;1mscripts/test\u001b[0m\nshell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}\nenv:\n pythonLocation: /opt/hostedtoolcache/Python/3.10.13/x64\n PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.10.13/x64/lib/pkgconfig\n Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.13/x64\n Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.13/x64\n Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.13/x64\n LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.10.13/x64/lib\n##[endgroup]\n+ [ -z true ]\n+ coverage run --debug config -m pytest\n-- config ----------------------------------------------------\n attempted_config_files: .coveragerc\n setup.cfg\n tox.ini\n pyproject.toml\n branch: False\n command_line: None\n concurrency: -none-\n config_file: /home/runner/work/uvicorn/uvicorn/pyproject.toml\n config_files_read: /home/runner/work/uvicorn/uvicorn/pyproject.toml\n context: None\n cover_pylib: False\n data_file: .coverage\n debug: config\n debug_file: None\n disable_warnings: -none-\n dynamic_context: None\n exclude_also: -none-\n exclude_list: pragma: no cover\n pragma: nocover\n if TYPE_CHECKING:\n if typing.TYPE_CHECKING:\n raise NotImplementedError\n py-not-win32\n py-linux\n py-gte-38\n py-gte-39\n py-gte-310\n py-lt-311\n extra_css: None\n fail_under: 98.35\n format: None\n html_dir: htmlcov\n html_skip_covered: None\n html_skip_empty: None\n html_title: Coverage report\n ignore_errors: False\n include_namespace_packages: False\n json_output: coverage.json\n json_pretty_print: False\n json_show_contexts: False\n lcov_output: coverage.lcov\n parallel: False\n partial_always_list: while (True|1|False|0):\n if (True|1|False|0):\n partial_list: #\\s*(pragma|PRAGMA)[:\\s]?\\s*(no|NO)\\s*(branch|BRANCH)\n paths: {}\n plugin_options: {'coverage_conditional_plugin': {'omit': {\"sys_platform == 'win32'\": ['uvicorn/loops/uvloop.py'], \"sys_platform != 'win32'\": ['uvicorn/loops/asyncio.py']}, 'rules': {'py-win32': \"sys_platform == 'win32'\", 'py-not-win32': \"sys_platform != 'win32'\", 'py-linux': \"sys_platform == 'linux'\", 'py-darwin': \"sys_platform == 'darwin'\", 'py-gte-38': 'sys_version_info >= (3, 8)', 'py-lt-38': 'sys_version_info < (3, 8)', 'py-gte-39': 'sys_version_info >= (3, 9)', 'py-lt-39': 'sys_version_info < (3, 9)', 'py-gte-310': 'sys_version_info >= (3, 10)', 'py-lt-310': 'sys_version_info < (3, 10)', 'py-gte-311': 'sys_version_info >= (3, 11)', 'py-lt-311': 'sys_version_info < (3, 11)'}}}\n plugins: coverage_conditional_plugin\n precision: 2\n relative_files: False\n report_contexts: None\n report_include: None\n report_omit: None\n run_include: -none-\n run_omit: uvicorn/workers.py\n uvicorn/__main__.py\n uvicorn/loops/asyncio.py\n show_contexts: False\n show_missing: True\n sigterm: False\n skip_covered: True\n skip_empty: False\n sort: None\n source: None\n source_pkgs: uvicorn\n tests\n timid: False\n xml_output: coverage.xml\n xml_package_depth: 99\n-- end -------------------------------------------------------\n============================= test session starts ==============================\nplatform linux -- Python 3.10.13, pytest-7.4.4, pluggy-1.3.0\nrootdir: /home/runner/work/uvicorn/uvicorn\nconfigfile: pyproject.toml\nplugins: anyio-3.7.1, mock-3.12.0\ncollected 565 items\n\ntests/test_auto_detection.py ... [ 0%]\ntests/test_cli.py .............. [ 3%]\ntests/test_config.py ................................................... [ 12%]\n........................................................ [ 21%]\ntests/test_default_headers.py ...... [ 23%]\ntests/test_lifespan.py ................ [ 25%]\ntests/test_main.py ......... [ 27%]\ntests/test_ssl.py .... [ 28%]\ntests/test_subprocess.py .. [ 28%]\ntests/importer/test_importer.py ....... [ 29%]\ntests/middleware/test_logging.py .............. [ 32%]\ntests/middleware/test_message_logger.py .. [ 32%]\ntests/middleware/test_proxy_headers.py ............... [ 35%]\ntests/middleware/test_wsgi.py ........... [ 37%]\ntests/protocols/test_http.py ........................................... [ 44%]\n............................................................... [ 55%]\ntests/protocols/test_utils.py ...... [ 56%]\ntests/protocols/test_websocket.py ...................................... [ 63%]\n........................................................................ [ 76%]\n........................................................FF......FF..FF.. [ 89%]\n.................... [ 92%]\ntests/supervisors/test_multiprocess.py . [ 92%]\ntests/supervisors/test_reload.py ..................................... [ 99%]\ntests/supervisors/test_signal.py ... [100%]\n\n=================================== FAILURES ===================================\n____ test_server_reject_connection_with_body_nolength[websockets-httptools] ____\n\n @contextlib.contextmanager\n def map_httpcore_exceptions() -> typing.Iterator[None]:\n try:\n> yield\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpx/_transports/default.py:67: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpx/_transports/default.py:371: in handle_async_request\n resp = await self._pool.handle_async_request(req)\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpcore/_async/connection_pool.py:268: in handle_async_request\n raise exc\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpcore/_async/connection_pool.py:251: in handle_async_request\n response = await connection.handle_async_request(request)\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpcore/_async/connection.py:103: in handle_async_request\n return await self._connection.handle_async_request(request)\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpcore/_async/http11.py:133: in handle_async_request\n raise exc\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpcore/_async/http11.py:111: in handle_async_request\n ) = await self._receive_response_headers(**kwargs)\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpcore/_async/http11.py:176: in _receive_response_headers\n event = await self._receive_event(timeout=timeout)\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <AsyncHTTP11Connection ['http://127.0.0.1:38783', CLOSED, Request Count: 1]>\ntimeout = 5.0\n\n async def _receive_event(\n self, timeout: Optional[float] = None\n ) -> Union[h11.Event, Type[h11.PAUSED]]:\n while True:\n with map_exceptions({h11.RemoteProtocolError: RemoteProtocolError}):\n event = self._h11_state.next_event()\n \n if event is h11.NEED_DATA:\n data = await self._network_stream.read(\n self.READ_NUM_BYTES, timeout=timeout\n )\n \n # If we feed this case through h11 we'll raise an exception like:\n #\n # httpcore.RemoteProtocolError: can't handle event type\n # ConnectionClosed when role=SERVER and state=SEND_RESPONSE\n #\n # Which is accurate, but not very informative from an end-user\n # perspective. Instead we handle this case distinctly and treat\n # it as a ConnectError.\n if data == b\"\" and self._h11_state.their_state == h11.SEND_RESPONSE:\n msg = \"Server disconnected without sending a response.\"\n> raise RemoteProtocolError(msg)\nE httpcore.RemoteProtocolError: Server disconnected without sending a response.\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpcore/_async/http11.py:226: RemoteProtocolError\n\nThe above exception was the direct cause of the following exception:\n\nws_protocol_cls = <class 'uvicorn.protocols.websockets.websockets_impl.WebSocketProtocol'>\nhttp_protocol_cls = <class 'uvicorn.protocols.http.httptools_impl.HttpToolsProtocol'>\nunused_tcp_port = 38783\n\n @pytest.mark.anyio\n async def test_server_reject_connection_with_body_nolength(\n ws_protocol_cls: \"typing.Type[WSProtocol | WebSocketProtocol]\",\n http_protocol_cls: \"typing.Type[H11Protocol | HttpToolsProtocol]\",\n unused_tcp_port: int,\n ):\n # test that the server can send a response with a body but no content-length\n async def app(scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable):\n assert scope[\"type\"] == \"websocket\"\n assert \"extensions\" in scope\n assert \"websocket.http.response\" in scope[\"extensions\"]\n \n # Pull up first recv message.\n message = await receive()\n assert message[\"type\"] == \"websocket.connect\"\n \n await send(\n {\n \"type\": \"websocket.http.response.start\",\n \"status\": 403,\n \"headers\": [],\n }\n )\n await send({\"type\": \"websocket.http.response.body\", \"body\": b\"hardbody\"})\n \n async def websocket_session(url):\n response = await wsresponse(url)\n assert response.status_code == 403\n assert response.content == b\"hardbody\"\n if ws_protocol_cls == WSProtocol: # pragma: no cover\n # wsproto automatically makes the message chunked\n assert response.headers[\"transfer-encoding\"] == \"chunked\"\n else: # pragma: no cover\n # websockets automatically adds a content-length\n assert response.headers[\"content-length\"] == \"8\"\n \n config = Config(\n app=app,\n ws=ws_protocol_cls,\n http=http_protocol_cls,\n lifespan=\"off\",\n port=unused_tcp_port,\n )\n async with run_server(config):\n> await websocket_session(f\"ws://127.0.0.1:{unused_tcp_port}\")\n\ntests/protocols/test_websocket.py:1219: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ntests/protocols/test_websocket.py:1201: in websocket_session\n response = await wsresponse(url)\ntests/protocols/test_websocket.py:73: in wsresponse\n return await client.get(url, headers=headers)\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpx/_client.py:1786: in get\n return await self.request(\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpx/_client.py:1559: in request\n return await self.send(request, auth=auth, follow_redirects=follow_redirects)\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpx/_client.py:1646: in send\n response = await self._send_handling_auth(\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpx/_client.py:1674: in _send_handling_auth\n response = await self._send_handling_redirects(\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpx/_client.py:1711: in _send_handling_redirects\n response = await self._send_single_request(request)\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpx/_client.py:1748: in _send_single_request\n response = await transport.handle_async_request(request)\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpx/_transports/default.py:370: in handle_async_request\n with map_httpcore_exceptions():\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/contextlib.py:153: in __exit__\n self.gen.throw(typ, value, traceback)\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n @contextlib.contextmanager\n def map_httpcore_exceptions() -> typing.Iterator[None]:\n try:\n yield\n except Exception as exc:\n mapped_exc = None\n \n for from_exc, to_exc in HTTPCORE_EXC_MAP.items():\n if not isinstance(exc, from_exc):\n continue\n # We want to map to the most specific exception we can find.\n # Eg if `exc` is an `httpcore.ReadTimeout`, we want to map to\n # `httpx.ReadTimeout`, not just `httpx.TimeoutException`.\n if mapped_exc is None or issubclass(to_exc, mapped_exc):\n mapped_exc = to_exc\n \n if mapped_exc is None: # pragma: no cover\n raise\n \n message = str(exc)\n> raise mapped_exc(message) from exc\nE httpx.RemoteProtocolError: Server disconnected without sending a response.\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpx/_transports/default.py:84: RemoteProtocolError\n----------------------------- Captured stderr call -----------------------------\nINFO: Started server process [2074]\nINFO: Uvicorn running on http://127.0.0.1:38783 (Press CTRL+C to quit)\nINFO: ('127.0.0.1', 55940) - \"WebSocket /\" 403\nINFO: connection rejected (403 Forbidden)\nINFO: connection closed\nINFO: Shutting down\n------------------------------ Captured log call -------------------------------\nINFO uvicorn.error:server.py:77 Started server process [2074]\nINFO uvicorn.error:server.py:219 Uvicorn running on http://127.0.0.1:38783 (Press CTRL+C to quit)\nINFO uvicorn.error:websockets_impl.py:317 ('127.0.0.1', 55940) - \"WebSocket /\" 403\nINFO uvicorn.error:server.py:229 connection rejected (403 Forbidden)\nINFO uvicorn.error:server.py:264 connection closed\nINFO uvicorn.error:server.py:265 Shutting down\n_______ test_server_reject_connection_with_body_nolength[websockets-h11] _______\n\n @contextlib.contextmanager\n def map_httpcore_exceptions() -> typing.Iterator[None]:\n try:\n> yield\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpx/_transports/default.py:67: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpx/_transports/default.py:371: in handle_async_request\n resp = await self._pool.handle_async_request(req)\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpcore/_async/connection_pool.py:268: in handle_async_request\n raise exc\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpcore/_async/connection_pool.py:251: in handle_async_request\n response = await connection.handle_async_request(request)\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpcore/_async/connection.py:103: in handle_async_request\n return await self._connection.handle_async_request(request)\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpcore/_async/http11.py:133: in handle_async_request\n raise exc\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpcore/_async/http11.py:111: in handle_async_request\n ) = await self._receive_response_headers(**kwargs)\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpcore/_async/http11.py:176: in _receive_response_headers\n event = await self._receive_event(timeout=timeout)\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <AsyncHTTP11Connection ['http://127.0.0.1:47113', CLOSED, Request Count: 1]>\ntimeout = 5.0\n\n async def _receive_event(\n self, timeout: Optional[float] = None\n ) -> Union[h11.Event, Type[h11.PAUSED]]:\n while True:\n with map_exceptions({h11.RemoteProtocolError: RemoteProtocolError}):\n event = self._h11_state.next_event()\n \n if event is h11.NEED_DATA:\n data = await self._network_stream.read(\n self.READ_NUM_BYTES, timeout=timeout\n )\n \n # If we feed this case through h11 we'll raise an exception like:\n #\n # httpcore.RemoteProtocolError: can't handle event type\n # ConnectionClosed when role=SERVER and state=SEND_RESPONSE\n #\n # Which is accurate, but not very informative from an end-user\n # perspective. Instead we handle this case distinctly and treat\n # it as a ConnectError.\n if data == b\"\" and self._h11_state.their_state == h11.SEND_RESPONSE:\n msg = \"Server disconnected without sending a response.\"\n> raise RemoteProtocolError(msg)\nE httpcore.RemoteProtocolError: Server disconnected without sending a response.\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpcore/_async/http11.py:226: RemoteProtocolError\n\nThe above exception was the direct cause of the following exception:\n\nws_protocol_cls = <class 'uvicorn.protocols.websockets.websockets_impl.WebSocketProtocol'>\nhttp_protocol_cls = <class 'uvicorn.protocols.http.h11_impl.H11Protocol'>\nunused_tcp_port = 47113\n\n @pytest.mark.anyio\n async def test_server_reject_connection_with_body_nolength(\n ws_protocol_cls: \"typing.Type[WSProtocol | WebSocketProtocol]\",\n http_protocol_cls: \"typing.Type[H11Protocol | HttpToolsProtocol]\",\n unused_tcp_port: int,\n ):\n # test that the server can send a response with a body but no content-length\n async def app(scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable):\n assert scope[\"type\"] == \"websocket\"\n assert \"extensions\" in scope\n assert \"websocket.http.response\" in scope[\"extensions\"]\n \n # Pull up first recv message.\n message = await receive()\n assert message[\"type\"] == \"websocket.connect\"\n \n await send(\n {\n \"type\": \"websocket.http.response.start\",\n \"status\": 403,\n \"headers\": [],\n }\n )\n await send({\"type\": \"websocket.http.response.body\", \"body\": b\"hardbody\"})\n \n async def websocket_session(url):\n response = await wsresponse(url)\n assert response.status_code == 403\n assert response.content == b\"hardbody\"\n if ws_protocol_cls == WSProtocol: # pragma: no cover\n # wsproto automatically makes the message chunked\n assert response.headers[\"transfer-encoding\"] == \"chunked\"\n else: # pragma: no cover\n # websockets automatically adds a content-length\n assert response.headers[\"content-length\"] == \"8\"\n \n config = Config(\n app=app,\n ws=ws_protocol_cls,\n http=http_protocol_cls,\n lifespan=\"off\",\n port=unused_tcp_port,\n )\n async with run_server(config):\n> await websocket_session(f\"ws://127.0.0.1:{unused_tcp_port}\")\n\ntests/protocols/test_websocket.py:1219: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ntests/protocols/test_websocket.py:1201: in websocket_session\n response = await wsresponse(url)\ntests/protocols/test_websocket.py:73: in wsresponse\n return await client.get(url, headers=headers)\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpx/_client.py:1786: in get\n return await self.request(\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpx/_client.py:1559: in request\n return await self.send(request, auth=auth, follow_redirects=follow_redirects)\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpx/_client.py:1646: in send\n response = await self._send_handling_auth(\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpx/_client.py:1674: in _send_handling_auth\n response = await self._send_handling_redirects(\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpx/_client.py:1711: in _send_handling_redirects\n response = await self._send_single_request(request)\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpx/_client.py:1748: in _send_single_request\n response = await transport.handle_async_request(request)\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpx/_transports/default.py:370: in handle_async_request\n with map_httpcore_exceptions():\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/contextlib.py:153: in __exit__\n self.gen.throw(typ, value, traceback)\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n @contextlib.contextmanager\n def map_httpcore_exceptions() -> typing.Iterator[None]:\n try:\n yield\n except Exception as exc:\n mapped_exc = None\n \n for from_exc, to_exc in HTTPCORE_EXC_MAP.items():\n if not isinstance(exc, from_exc):\n continue\n # We want to map to the most specific exception we can find.\n # Eg if `exc` is an `httpcore.ReadTimeout`, we want to map to\n # `httpx.ReadTimeout`, not just `httpx.TimeoutException`.\n if mapped_exc is None or issubclass(to_exc, mapped_exc):\n mapped_exc = to_exc\n \n if mapped_exc is None: # pragma: no cover\n raise\n \n message = str(exc)\n> raise mapped_exc(message) from exc\nE httpx.RemoteProtocolError: Server disconnected without sending a response.\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/httpx/_transports/default.py:84: RemoteProtocolError\n----------------------------- Captured stderr call -----------------------------\nINFO: Started server process [2074]\nINFO: Uvicorn running on http://127.0.0.1:47113 (Press CTRL+C to quit)\nINFO: ('127.0.0.1', 38322) - \"WebSocket /\" 403\nINFO: connection rejected (403 Forbidden)\nINFO: connection closed\nINFO: Shutting down\n------------------------------ Captured log call -------------------------------\nINFO uvicorn.error:server.py:77 Started server process [2074]\nINFO uvicorn.error:server.py:219 Uvicorn running on http://127.0.0.1:47113 (Press CTRL+C to quit)\nINFO uvicorn.error:websockets_impl.py:317 ('127.0.0.1', 38322) - \"WebSocket /\" 403\nINFO uvicorn.error:server.py:229 connection rejected (403 Forbidden)\nINFO uvicorn.error:server.py:264 connection closed\nINFO uvicorn.error:server.py:265 Shutting down\n____ test_server_reject_connection_with_missing_body[websockets-httptools] _____\n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x560257c7aaa0>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n> status_line = await read_line(stream)\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/http.py:120: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x560257c7aaa0>>\n\n async def read_line(stream: asyncio.StreamReader) -> bytes:\n \"\"\"\n Read a single line from ``stream``.\n \n CRLF is stripped from the return value.\n \n \"\"\"\n # Security: this is bounded by the StreamReader's limit (default = 32\u00a0KiB).\n line = await stream.readline()\n # Security: this guarantees header values are small (hard-coded = 8\u00a0KiB)\n if len(line) > MAX_LINE:\n raise SecurityError(\"line too long\")\n # Not mandatory but safe - https://www.rfc-editor.org/rfc/rfc7230.html#section-3.5\n if not line.endswith(b\"\\r\\n\"):\n> raise EOFError(\"line without CRLF\")\nE EOFError: line without CRLF\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/http.py:200: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7f6141edb670>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n> status_code, reason, headers = await read_response(self.reader)\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:139: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x560257c7aaa0>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n status_line = await read_line(stream)\n except EOFError as exc:\n> raise EOFError(\"connection closed while reading HTTP status line\") from exc\nE EOFError: connection closed while reading HTTP status line\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/http.py:122: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nws_protocol_cls = <class 'uvicorn.protocols.websockets.websockets_impl.WebSocketProtocol'>\nhttp_protocol_cls = <class 'uvicorn.protocols.http.httptools_impl.HttpToolsProtocol'>\nunused_tcp_port = 42645\n\n @pytest.mark.anyio\n async def test_server_reject_connection_with_missing_body(\n ws_protocol_cls: \"typing.Type[WSProtocol | WebSocketProtocol]\",\n http_protocol_cls: \"typing.Type[H11Protocol | HttpToolsProtocol]\",\n unused_tcp_port: int,\n ):\n async def app(scope, receive, send):\n assert scope[\"type\"] == \"websocket\"\n assert \"websocket.http.response\" in scope[\"extensions\"]\n \n # Pull up first recv message.\n message = await receive()\n assert message[\"type\"] == \"websocket.connect\"\n \n message = {\n \"type\": \"websocket.http.response.start\",\n \"status\": 404,\n \"headers\": [(b\"Content-Length\", b\"0\"), (b\"Content-Type\", b\"text/plain\")],\n }\n await send(message)\n # no further message\n \n async def websocket_session(url):\n with pytest.raises(websockets.exceptions.InvalidStatusCode) as exc_info:\n async with websockets.client.connect(url):\n pass # pragma: no cover\n assert exc_info.value.status_code == 404\n \n config = Config(\n app=app,\n ws=ws_protocol_cls,\n http=http_protocol_cls,\n lifespan=\"off\",\n port=unused_tcp_port,\n )\n async with run_server(config):\n> await websocket_session(f\"ws://127.0.0.1:{unused_tcp_port}\")\n\ntests/protocols/test_websocket.py:1298: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ntests/protocols/test_websocket.py:1286: in websocket_session\n async with websockets.client.connect(url):\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:629: in __aenter__\n return await self\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:647: in __await_impl_timeout__\n return await self.__await_impl__()\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:654: in __await_impl__\n await protocol.handshake(\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:319: in handshake\n status_code, response_headers = await self.read_http_response()\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7f6141edb670>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n status_code, reason, headers = await read_response(self.reader)\n except Exception as exc:\n> raise InvalidMessage(\"did not receive a valid HTTP response\") from exc\nE websockets.exceptions.InvalidMessage: did not receive a valid HTTP response\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:141: InvalidMessage\n----------------------------- Captured stderr call -----------------------------\nINFO: Started server process [2074]\nINFO: Uvicorn running on http://127.0.0.1:42645 (Press CTRL+C to quit)\nINFO: ('127.0.0.1', 49068) - \"WebSocket /\" 404\nINFO: connection rejected (404 Not Found)\nINFO: connection closed\nINFO: Shutting down\n------------------------------ Captured log call -------------------------------\nINFO uvicorn.error:server.py:77 Started server process [2074]\nINFO uvicorn.error:server.py:219 Uvicorn running on http://127.0.0.1:42645 (Press CTRL+C to quit)\nINFO uvicorn.error:websockets_impl.py:317 ('127.0.0.1', 49068) - \"WebSocket /\" 404\nINFO uvicorn.error:server.py:229 connection rejected (404 Not Found)\nINFO uvicorn.error:server.py:264 connection closed\nINFO uvicorn.error:server.py:265 Shutting down\n_______ test_server_reject_connection_with_missing_body[websockets-h11] ________\n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x560257c7a7f0>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n> status_line = await read_line(stream)\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/http.py:120: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x560257c7a7f0>>\n\n async def read_line(stream: asyncio.StreamReader) -> bytes:\n \"\"\"\n Read a single line from ``stream``.\n \n CRLF is stripped from the return value.\n \n \"\"\"\n # Security: this is bounded by the StreamReader's limit (default = 32\u00a0KiB).\n line = await stream.readline()\n # Security: this guarantees header values are small (hard-coded = 8\u00a0KiB)\n if len(line) > MAX_LINE:\n raise SecurityError(\"line too long\")\n # Not mandatory but safe - https://www.rfc-editor.org/rfc/rfc7230.html#section-3.5\n if not line.endswith(b\"\\r\\n\"):\n> raise EOFError(\"line without CRLF\")\nE EOFError: line without CRLF\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/http.py:200: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7f6141f96020>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n> status_code, reason, headers = await read_response(self.reader)\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:139: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x560257c7a7f0>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n status_line = await read_line(stream)\n except EOFError as exc:\n> raise EOFError(\"connection closed while reading HTTP status line\") from exc\nE EOFError: connection closed while reading HTTP status line\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/http.py:122: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nws_protocol_cls = <class 'uvicorn.protocols.websockets.websockets_impl.WebSocketProtocol'>\nhttp_protocol_cls = <class 'uvicorn.protocols.http.h11_impl.H11Protocol'>\nunused_tcp_port = 49901\n\n @pytest.mark.anyio\n async def test_server_reject_connection_with_missing_body(\n ws_protocol_cls: \"typing.Type[WSProtocol | WebSocketProtocol]\",\n http_protocol_cls: \"typing.Type[H11Protocol | HttpToolsProtocol]\",\n unused_tcp_port: int,\n ):\n async def app(scope, receive, send):\n assert scope[\"type\"] == \"websocket\"\n assert \"websocket.http.response\" in scope[\"extensions\"]\n \n # Pull up first recv message.\n message = await receive()\n assert message[\"type\"] == \"websocket.connect\"\n \n message = {\n \"type\": \"websocket.http.response.start\",\n \"status\": 404,\n \"headers\": [(b\"Content-Length\", b\"0\"), (b\"Content-Type\", b\"text/plain\")],\n }\n await send(message)\n # no further message\n \n async def websocket_session(url):\n with pytest.raises(websockets.exceptions.InvalidStatusCode) as exc_info:\n async with websockets.client.connect(url):\n pass # pragma: no cover\n assert exc_info.value.status_code == 404\n \n config = Config(\n app=app,\n ws=ws_protocol_cls,\n http=http_protocol_cls,\n lifespan=\"off\",\n port=unused_tcp_port,\n )\n async with run_server(config):\n> await websocket_session(f\"ws://127.0.0.1:{unused_tcp_port}\")\n\ntests/protocols/test_websocket.py:1298: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ntests/protocols/test_websocket.py:1286: in websocket_session\n async with websockets.client.connect(url):\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:629: in __aenter__\n return await self\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:647: in __await_impl_timeout__\n return await self.__await_impl__()\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:654: in __await_impl__\n await protocol.handshake(\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:319: in handshake\n status_code, response_headers = await self.read_http_response()\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7f6141f96020>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n status_code, reason, headers = await read_response(self.reader)\n except Exception as exc:\n> raise InvalidMessage(\"did not receive a valid HTTP response\") from exc\nE websockets.exceptions.InvalidMessage: did not receive a valid HTTP response\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:141: InvalidMessage\n----------------------------- Captured stderr call -----------------------------\nINFO: Started server process [2074]\nINFO: Uvicorn running on http://127.0.0.1:49901 (Press CTRL+C to quit)\nINFO: ('127.0.0.1', 53884) - \"WebSocket /\" 404\nINFO: connection rejected (404 Not Found)\nINFO: connection closed\nINFO: Shutting down\n------------------------------ Captured log call -------------------------------\nINFO uvicorn.error:server.py:77 Started server process [2074]\nINFO uvicorn.error:server.py:219 Uvicorn running on http://127.0.0.1:49901 (Press CTRL+C to quit)\nINFO uvicorn.error:websockets_impl.py:317 ('127.0.0.1', 53884) - \"WebSocket /\" 404\nINFO uvicorn.error:server.py:229 connection rejected (404 Not Found)\nINFO uvicorn.error:server.py:264 connection closed\nINFO uvicorn.error:server.py:265 Shutting down\n_ test_server_multiple_websocket_http_response_start_events[websockets-httptools] _\n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x560258130900>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n> status_line = await read_line(stream)\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/http.py:120: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x560258130900>>\n\n async def read_line(stream: asyncio.StreamReader) -> bytes:\n \"\"\"\n Read a single line from ``stream``.\n \n CRLF is stripped from the return value.\n \n \"\"\"\n # Security: this is bounded by the StreamReader's limit (default = 32\u00a0KiB).\n line = await stream.readline()\n # Security: this guarantees header values are small (hard-coded = 8\u00a0KiB)\n if len(line) > MAX_LINE:\n raise SecurityError(\"line too long\")\n # Not mandatory but safe - https://www.rfc-editor.org/rfc/rfc7230.html#section-3.5\n if not line.endswith(b\"\\r\\n\"):\n> raise EOFError(\"line without CRLF\")\nE EOFError: line without CRLF\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/http.py:200: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7f6141fdcfd0>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n> status_code, reason, headers = await read_response(self.reader)\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:139: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x560258130900>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n status_line = await read_line(stream)\n except EOFError as exc:\n> raise EOFError(\"connection closed while reading HTTP status line\") from exc\nE EOFError: connection closed while reading HTTP status line\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/http.py:122: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nws_protocol_cls = <class 'uvicorn.protocols.websockets.websockets_impl.WebSocketProtocol'>\nhttp_protocol_cls = <class 'uvicorn.protocols.http.httptools_impl.HttpToolsProtocol'>\nunused_tcp_port = 54991\n\n @pytest.mark.anyio\n async def test_server_multiple_websocket_http_response_start_events(\n ws_protocol_cls: \"typing.Type[WSProtocol | WebSocketProtocol]\",\n http_protocol_cls: \"typing.Type[H11Protocol | HttpToolsProtocol]\",\n unused_tcp_port: int,\n ):\n \"\"\"\n The server should raise an exception if it sends multiple\n websocket.http.response.start events.\n \"\"\"\n exception_message: typing.Optional[str] = None\n \n async def app(scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable):\n nonlocal exception_message\n assert scope[\"type\"] == \"websocket\"\n assert \"extensions\" in scope\n assert \"websocket.http.response\" in scope[\"extensions\"]\n \n # Pull up first recv message.\n message = await receive()\n assert message[\"type\"] == \"websocket.connect\"\n \n start_event: WebSocketResponseStartEvent = {\n \"type\": \"websocket.http.response.start\",\n \"status\": 404,\n \"headers\": [(b\"Content-Length\", b\"0\"), (b\"Content-Type\", b\"text/plain\")],\n }\n await send(start_event)\n try:\n await send(start_event)\n except Exception as exc:\n exception_message = str(exc)\n \n async def websocket_session(url: str):\n with pytest.raises(websockets.exceptions.InvalidStatusCode) as exc_info:\n async with websockets.client.connect(url):\n pass\n assert exc_info.value.status_code == 404\n \n config = Config(\n app=app,\n ws=ws_protocol_cls,\n http=http_protocol_cls,\n lifespan=\"off\",\n port=unused_tcp_port,\n )\n async with run_server(config):\n> await websocket_session(f\"ws://127.0.0.1:{unused_tcp_port}\")\n\ntests/protocols/test_websocket.py:1348: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ntests/protocols/test_websocket.py:1336: in websocket_session\n async with websockets.client.connect(url):\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:629: in __aenter__\n return await self\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:647: in __await_impl_timeout__\n return await self.__await_impl__()\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:654: in __await_impl__\n await protocol.handshake(\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:319: in handshake\n status_code, response_headers = await self.read_http_response()\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7f6141fdcfd0>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n status_code, reason, headers = await read_response(self.reader)\n except Exception as exc:\n> raise InvalidMessage(\"did not receive a valid HTTP response\") from exc\nE websockets.exceptions.InvalidMessage: did not receive a valid HTTP response\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:141: InvalidMessage\n----------------------------- Captured stderr call -----------------------------\nINFO: Started server process [2074]\nINFO: Uvicorn running on http://127.0.0.1:54991 (Press CTRL+C to quit)\nINFO: ('127.0.0.1', 39844) - \"WebSocket /\" 404\nINFO: connection rejected (404 Not Found)\nINFO: connection closed\nINFO: Shutting down\n------------------------------ Captured log call -------------------------------\nINFO uvicorn.error:server.py:77 Started server process [2074]\nINFO uvicorn.error:server.py:219 Uvicorn running on http://127.0.0.1:54991 (Press CTRL+C to quit)\nINFO uvicorn.error:websockets_impl.py:317 ('127.0.0.1', 39844) - \"WebSocket /\" 404\nINFO uvicorn.error:server.py:229 connection rejected (404 Not Found)\nINFO uvicorn.error:server.py:264 connection closed\nINFO uvicorn.error:server.py:265 Shutting down\n__ test_server_multiple_websocket_http_response_start_events[websockets-h11] ___\n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x5602580388e0>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n> status_line = await read_line(stream)\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/http.py:120: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x5602580388e0>>\n\n async def read_line(stream: asyncio.StreamReader) -> bytes:\n \"\"\"\n Read a single line from ``stream``.\n \n CRLF is stripped from the return value.\n \n \"\"\"\n # Security: this is bounded by the StreamReader's limit (default = 32\u00a0KiB).\n line = await stream.readline()\n # Security: this guarantees header values are small (hard-coded = 8\u00a0KiB)\n if len(line) > MAX_LINE:\n raise SecurityError(\"line too long\")\n # Not mandatory but safe - https://www.rfc-editor.org/rfc/rfc7230.html#section-3.5\n if not line.endswith(b\"\\r\\n\"):\n> raise EOFError(\"line without CRLF\")\nE EOFError: line without CRLF\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/http.py:200: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7f6141ca2ad0>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n> status_code, reason, headers = await read_response(self.reader)\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:139: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x5602580388e0>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n status_line = await read_line(stream)\n except EOFError as exc:\n> raise EOFError(\"connection closed while reading HTTP status line\") from exc\nE EOFError: connection closed while reading HTTP status line\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/http.py:122: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nws_protocol_cls = <class 'uvicorn.protocols.websockets.websockets_impl.WebSocketProtocol'>\nhttp_protocol_cls = <class 'uvicorn.protocols.http.h11_impl.H11Protocol'>\nunused_tcp_port = 57457\n\n @pytest.mark.anyio\n async def test_server_multiple_websocket_http_response_start_events(\n ws_protocol_cls: \"typing.Type[WSProtocol | WebSocketProtocol]\",\n http_protocol_cls: \"typing.Type[H11Protocol | HttpToolsProtocol]\",\n unused_tcp_port: int,\n ):\n \"\"\"\n The server should raise an exception if it sends multiple\n websocket.http.response.start events.\n \"\"\"\n exception_message: typing.Optional[str] = None\n \n async def app(scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable):\n nonlocal exception_message\n assert scope[\"type\"] == \"websocket\"\n assert \"extensions\" in scope\n assert \"websocket.http.response\" in scope[\"extensions\"]\n \n # Pull up first recv message.\n message = await receive()\n assert message[\"type\"] == \"websocket.connect\"\n \n start_event: WebSocketResponseStartEvent = {\n \"type\": \"websocket.http.response.start\",\n \"status\": 404,\n \"headers\": [(b\"Content-Length\", b\"0\"), (b\"Content-Type\", b\"text/plain\")],\n }\n await send(start_event)\n try:\n await send(start_event)\n except Exception as exc:\n exception_message = str(exc)\n \n async def websocket_session(url: str):\n with pytest.raises(websockets.exceptions.InvalidStatusCode) as exc_info:\n async with websockets.client.connect(url):\n pass\n assert exc_info.value.status_code == 404\n \n config = Config(\n app=app,\n ws=ws_protocol_cls,\n http=http_protocol_cls,\n lifespan=\"off\",\n port=unused_tcp_port,\n )\n async with run_server(config):\n> await websocket_session(f\"ws://127.0.0.1:{unused_tcp_port}\")\n\ntests/protocols/test_websocket.py:1348: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ntests/protocols/test_websocket.py:1336: in websocket_session\n async with websockets.client.connect(url):\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:629: in __aenter__\n return await self\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:647: in __await_impl_timeout__\n return await self.__await_impl__()\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:654: in __await_impl__\n await protocol.handshake(\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:319: in handshake\n status_code, response_headers = await self.read_http_response()\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7f6141ca2ad0>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n status_code, reason, headers = await read_response(self.reader)\n except Exception as exc:\n> raise InvalidMessage(\"did not receive a valid HTTP response\") from exc\nE websockets.exceptions.InvalidMessage: did not receive a valid HTTP response\n\n/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/websockets/legacy/client.py:141: InvalidMessage\n----------------------------- Captured stderr call -----------------------------\nINFO: Started server process [2074]\nINFO: Uvicorn running on http://127.0.0.1:57457 (Press CTRL+C to quit)\nINFO: ('127.0.0.1', 39068) - \"WebSocket /\" 404\nINFO: connection rejected (404 Not Found)\nINFO: connection closed\nINFO: Shutting down\n------------------------------ Captured log call -------------------------------\nINFO uvicorn.error:server.py:77 Started server process [2074]\nINFO uvicorn.error:server.py:219 Uvicorn running on http://127.0.0.1:57457 (Press CTRL+C to quit)\nINFO uvicorn.error:websockets_impl.py:317 ('127.0.0.1', 39068) - \"WebSocket /\" 404\nINFO uvicorn.error:server.py:229 connection rejected (404 Not Found)\nINFO uvicorn.error:server.py:264 connection closed\nINFO uvicorn.error:server.py:265 Shutting down\n=================== 6 failed, 559 passed in 66.13s (0:01:06) ===================\n##[error]Process completed with exit code 1.\n"}, {"step_name": "Python 3.11 ubuntu-latest/7_Run tests.txt", "log": "##[group]Run scripts/test\n\u001b[36;1mscripts/test\u001b[0m\nshell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}\nenv:\n pythonLocation: /opt/hostedtoolcache/Python/3.11.7/x64\n PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.11.7/x64/lib/pkgconfig\n Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.7/x64\n Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.7/x64\n Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.7/x64\n LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.11.7/x64/lib\n##[endgroup]\n+ [ -z true ]\n+ coverage run --debug config -m pytest\n-- config ----------------------------------------------------\n attempted_config_files: .coveragerc\n setup.cfg\n tox.ini\n pyproject.toml\n branch: False\n command_line: None\n concurrency: -none-\n config_file: /home/runner/work/uvicorn/uvicorn/pyproject.toml\n config_files_read: /home/runner/work/uvicorn/uvicorn/pyproject.toml\n context: None\n cover_pylib: False\n data_file: .coverage\n debug: config\n debug_file: None\n disable_warnings: -none-\n dynamic_context: None\n exclude_also: -none-\n exclude_list: pragma: no cover\n pragma: nocover\n if TYPE_CHECKING:\n if typing.TYPE_CHECKING:\n raise NotImplementedError\n py-not-win32\n py-linux\n py-gte-38\n py-gte-39\n py-gte-310\n py-gte-311\n extra_css: None\n fail_under: 98.35\n format: None\n html_dir: htmlcov\n html_skip_covered: None\n html_skip_empty: None\n html_title: Coverage report\n ignore_errors: False\n include_namespace_packages: False\n json_output: coverage.json\n json_pretty_print: False\n json_show_contexts: False\n lcov_output: coverage.lcov\n parallel: False\n partial_always_list: while (True|1|False|0):\n if (True|1|False|0):\n partial_list: #\\s*(pragma|PRAGMA)[:\\s]?\\s*(no|NO)\\s*(branch|BRANCH)\n paths: {}\n plugin_options: {'coverage_conditional_plugin': {'omit': {\"sys_platform == 'win32'\": ['uvicorn/loops/uvloop.py'], \"sys_platform != 'win32'\": ['uvicorn/loops/asyncio.py']}, 'rules': {'py-win32': \"sys_platform == 'win32'\", 'py-not-win32': \"sys_platform != 'win32'\", 'py-linux': \"sys_platform == 'linux'\", 'py-darwin': \"sys_platform == 'darwin'\", 'py-gte-38': 'sys_version_info >= (3, 8)', 'py-lt-38': 'sys_version_info < (3, 8)', 'py-gte-39': 'sys_version_info >= (3, 9)', 'py-lt-39': 'sys_version_info < (3, 9)', 'py-gte-310': 'sys_version_info >= (3, 10)', 'py-lt-310': 'sys_version_info < (3, 10)', 'py-gte-311': 'sys_version_info >= (3, 11)', 'py-lt-311': 'sys_version_info < (3, 11)'}}}\n plugins: coverage_conditional_plugin\n precision: 2\n relative_files: False\n report_contexts: None\n report_include: None\n report_omit: None\n run_include: -none-\n run_omit: uvicorn/workers.py\n uvicorn/__main__.py\n uvicorn/loops/asyncio.py\n show_contexts: False\n show_missing: True\n sigterm: False\n skip_covered: True\n skip_empty: False\n sort: None\n source: None\n source_pkgs: uvicorn\n tests\n timid: False\n xml_output: coverage.xml\n xml_package_depth: 99\n-- end -------------------------------------------------------\n============================= test session starts ==============================\nplatform linux -- Python 3.11.7, pytest-7.4.4, pluggy-1.3.0\nrootdir: /home/runner/work/uvicorn/uvicorn\nconfigfile: pyproject.toml\nplugins: anyio-3.7.1, mock-3.12.0\ncollected 565 items\n\ntests/test_auto_detection.py ... [ 0%]\ntests/test_cli.py .............. [ 3%]\ntests/test_config.py ................................................... [ 12%]\n........................................................ [ 21%]\ntests/test_default_headers.py ...... [ 23%]\ntests/test_lifespan.py ................ [ 25%]\ntests/test_main.py ......... [ 27%]\ntests/test_ssl.py .... [ 28%]\ntests/test_subprocess.py .. [ 28%]\ntests/importer/test_importer.py ....... [ 29%]\ntests/middleware/test_logging.py .............. [ 32%]\ntests/middleware/test_message_logger.py .. [ 32%]\ntests/middleware/test_proxy_headers.py ............... [ 35%]\ntests/middleware/test_wsgi.py ........... [ 37%]\ntests/protocols/test_http.py ........................................... [ 44%]\n............................................................... [ 55%]\ntests/protocols/test_utils.py ...... [ 56%]\ntests/protocols/test_websocket.py ...................................... [ 63%]\n........................................................................ [ 76%]\n........................................................FF......FF..FF.. [ 89%]\n.................... [ 92%]\ntests/supervisors/test_multiprocess.py . [ 92%]\ntests/supervisors/test_reload.py ..................................... [ 99%]\ntests/supervisors/test_signal.py ... [100%]\n\n=================================== FAILURES ===================================\n____ test_server_reject_connection_with_body_nolength[websockets-httptools] ____\n\n @contextlib.contextmanager\n def map_httpcore_exceptions() -> typing.Iterator[None]:\n try:\n> yield\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpx/_transports/default.py:67: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpx/_transports/default.py:371: in handle_async_request\n resp = await self._pool.handle_async_request(req)\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpcore/_async/connection_pool.py:268: in handle_async_request\n raise exc\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpcore/_async/connection_pool.py:251: in handle_async_request\n response = await connection.handle_async_request(request)\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpcore/_async/connection.py:103: in handle_async_request\n return await self._connection.handle_async_request(request)\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpcore/_async/http11.py:133: in handle_async_request\n raise exc\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpcore/_async/http11.py:111: in handle_async_request\n ) = await self._receive_response_headers(**kwargs)\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpcore/_async/http11.py:176: in _receive_response_headers\n event = await self._receive_event(timeout=timeout)\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <AsyncHTTP11Connection ['http://127.0.0.1:58977', CLOSED, Request Count: 1]>\ntimeout = 5.0\n\n async def _receive_event(\n self, timeout: Optional[float] = None\n ) -> Union[h11.Event, Type[h11.PAUSED]]:\n while True:\n with map_exceptions({h11.RemoteProtocolError: RemoteProtocolError}):\n event = self._h11_state.next_event()\n \n if event is h11.NEED_DATA:\n data = await self._network_stream.read(\n self.READ_NUM_BYTES, timeout=timeout\n )\n \n # If we feed this case through h11 we'll raise an exception like:\n #\n # httpcore.RemoteProtocolError: can't handle event type\n # ConnectionClosed when role=SERVER and state=SEND_RESPONSE\n #\n # Which is accurate, but not very informative from an end-user\n # perspective. Instead we handle this case distinctly and treat\n # it as a ConnectError.\n if data == b\"\" and self._h11_state.their_state == h11.SEND_RESPONSE:\n msg = \"Server disconnected without sending a response.\"\n> raise RemoteProtocolError(msg)\nE httpcore.RemoteProtocolError: Server disconnected without sending a response.\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpcore/_async/http11.py:226: RemoteProtocolError\n\nThe above exception was the direct cause of the following exception:\n\nws_protocol_cls = <class 'uvicorn.protocols.websockets.websockets_impl.WebSocketProtocol'>\nhttp_protocol_cls = <class 'uvicorn.protocols.http.httptools_impl.HttpToolsProtocol'>\nunused_tcp_port = 58977\n\n @pytest.mark.anyio\n async def test_server_reject_connection_with_body_nolength(\n ws_protocol_cls: \"typing.Type[WSProtocol | WebSocketProtocol]\",\n http_protocol_cls: \"typing.Type[H11Protocol | HttpToolsProtocol]\",\n unused_tcp_port: int,\n ):\n # test that the server can send a response with a body but no content-length\n async def app(scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable):\n assert scope[\"type\"] == \"websocket\"\n assert \"extensions\" in scope\n assert \"websocket.http.response\" in scope[\"extensions\"]\n \n # Pull up first recv message.\n message = await receive()\n assert message[\"type\"] == \"websocket.connect\"\n \n await send(\n {\n \"type\": \"websocket.http.response.start\",\n \"status\": 403,\n \"headers\": [],\n }\n )\n await send({\"type\": \"websocket.http.response.body\", \"body\": b\"hardbody\"})\n \n async def websocket_session(url):\n response = await wsresponse(url)\n assert response.status_code == 403\n assert response.content == b\"hardbody\"\n if ws_protocol_cls == WSProtocol: # pragma: no cover\n # wsproto automatically makes the message chunked\n assert response.headers[\"transfer-encoding\"] == \"chunked\"\n else: # pragma: no cover\n # websockets automatically adds a content-length\n assert response.headers[\"content-length\"] == \"8\"\n \n config = Config(\n app=app,\n ws=ws_protocol_cls,\n http=http_protocol_cls,\n lifespan=\"off\",\n port=unused_tcp_port,\n )\n async with run_server(config):\n> await websocket_session(f\"ws://127.0.0.1:{unused_tcp_port}\")\n\ntests/protocols/test_websocket.py:1219: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ntests/protocols/test_websocket.py:1201: in websocket_session\n response = await wsresponse(url)\ntests/protocols/test_websocket.py:73: in wsresponse\n return await client.get(url, headers=headers)\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpx/_client.py:1786: in get\n return await self.request(\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpx/_client.py:1559: in request\n return await self.send(request, auth=auth, follow_redirects=follow_redirects)\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpx/_client.py:1646: in send\n response = await self._send_handling_auth(\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpx/_client.py:1674: in _send_handling_auth\n response = await self._send_handling_redirects(\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpx/_client.py:1711: in _send_handling_redirects\n response = await self._send_single_request(request)\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpx/_client.py:1748: in _send_single_request\n response = await transport.handle_async_request(request)\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpx/_transports/default.py:370: in handle_async_request\n with map_httpcore_exceptions():\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/contextlib.py:158: in __exit__\n self.gen.throw(typ, value, traceback)\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n @contextlib.contextmanager\n def map_httpcore_exceptions() -> typing.Iterator[None]:\n try:\n yield\n except Exception as exc:\n mapped_exc = None\n \n for from_exc, to_exc in HTTPCORE_EXC_MAP.items():\n if not isinstance(exc, from_exc):\n continue\n # We want to map to the most specific exception we can find.\n # Eg if `exc` is an `httpcore.ReadTimeout`, we want to map to\n # `httpx.ReadTimeout`, not just `httpx.TimeoutException`.\n if mapped_exc is None or issubclass(to_exc, mapped_exc):\n mapped_exc = to_exc\n \n if mapped_exc is None: # pragma: no cover\n raise\n \n message = str(exc)\n> raise mapped_exc(message) from exc\nE httpx.RemoteProtocolError: Server disconnected without sending a response.\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpx/_transports/default.py:84: RemoteProtocolError\n----------------------------- Captured stderr call -----------------------------\nINFO: Started server process [1915]\nINFO: Uvicorn running on http://127.0.0.1:58977 (Press CTRL+C to quit)\nINFO: ('127.0.0.1', 39748) - \"WebSocket /\" 403\nINFO: connection rejected (403 Forbidden)\nINFO: connection closed\nINFO: Shutting down\n------------------------------ Captured log call -------------------------------\nINFO uvicorn.error:server.py:77 Started server process [1915]\nINFO uvicorn.error:server.py:219 Uvicorn running on http://127.0.0.1:58977 (Press CTRL+C to quit)\nINFO uvicorn.error:websockets_impl.py:317 ('127.0.0.1', 39748) - \"WebSocket /\" 403\nINFO uvicorn.error:server.py:229 connection rejected (403 Forbidden)\nINFO uvicorn.error:server.py:264 connection closed\nINFO uvicorn.error:server.py:265 Shutting down\n_______ test_server_reject_connection_with_body_nolength[websockets-h11] _______\n\n @contextlib.contextmanager\n def map_httpcore_exceptions() -> typing.Iterator[None]:\n try:\n> yield\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpx/_transports/default.py:67: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpx/_transports/default.py:371: in handle_async_request\n resp = await self._pool.handle_async_request(req)\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpcore/_async/connection_pool.py:268: in handle_async_request\n raise exc\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpcore/_async/connection_pool.py:251: in handle_async_request\n response = await connection.handle_async_request(request)\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpcore/_async/connection.py:103: in handle_async_request\n return await self._connection.handle_async_request(request)\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpcore/_async/http11.py:133: in handle_async_request\n raise exc\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpcore/_async/http11.py:111: in handle_async_request\n ) = await self._receive_response_headers(**kwargs)\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpcore/_async/http11.py:176: in _receive_response_headers\n event = await self._receive_event(timeout=timeout)\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <AsyncHTTP11Connection ['http://127.0.0.1:34651', CLOSED, Request Count: 1]>\ntimeout = 5.0\n\n async def _receive_event(\n self, timeout: Optional[float] = None\n ) -> Union[h11.Event, Type[h11.PAUSED]]:\n while True:\n with map_exceptions({h11.RemoteProtocolError: RemoteProtocolError}):\n event = self._h11_state.next_event()\n \n if event is h11.NEED_DATA:\n data = await self._network_stream.read(\n self.READ_NUM_BYTES, timeout=timeout\n )\n \n # If we feed this case through h11 we'll raise an exception like:\n #\n # httpcore.RemoteProtocolError: can't handle event type\n # ConnectionClosed when role=SERVER and state=SEND_RESPONSE\n #\n # Which is accurate, but not very informative from an end-user\n # perspective. Instead we handle this case distinctly and treat\n # it as a ConnectError.\n if data == b\"\" and self._h11_state.their_state == h11.SEND_RESPONSE:\n msg = \"Server disconnected without sending a response.\"\n> raise RemoteProtocolError(msg)\nE httpcore.RemoteProtocolError: Server disconnected without sending a response.\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpcore/_async/http11.py:226: RemoteProtocolError\n\nThe above exception was the direct cause of the following exception:\n\nws_protocol_cls = <class 'uvicorn.protocols.websockets.websockets_impl.WebSocketProtocol'>\nhttp_protocol_cls = <class 'uvicorn.protocols.http.h11_impl.H11Protocol'>\nunused_tcp_port = 34651\n\n @pytest.mark.anyio\n async def test_server_reject_connection_with_body_nolength(\n ws_protocol_cls: \"typing.Type[WSProtocol | WebSocketProtocol]\",\n http_protocol_cls: \"typing.Type[H11Protocol | HttpToolsProtocol]\",\n unused_tcp_port: int,\n ):\n # test that the server can send a response with a body but no content-length\n async def app(scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable):\n assert scope[\"type\"] == \"websocket\"\n assert \"extensions\" in scope\n assert \"websocket.http.response\" in scope[\"extensions\"]\n \n # Pull up first recv message.\n message = await receive()\n assert message[\"type\"] == \"websocket.connect\"\n \n await send(\n {\n \"type\": \"websocket.http.response.start\",\n \"status\": 403,\n \"headers\": [],\n }\n )\n await send({\"type\": \"websocket.http.response.body\", \"body\": b\"hardbody\"})\n \n async def websocket_session(url):\n response = await wsresponse(url)\n assert response.status_code == 403\n assert response.content == b\"hardbody\"\n if ws_protocol_cls == WSProtocol: # pragma: no cover\n # wsproto automatically makes the message chunked\n assert response.headers[\"transfer-encoding\"] == \"chunked\"\n else: # pragma: no cover\n # websockets automatically adds a content-length\n assert response.headers[\"content-length\"] == \"8\"\n \n config = Config(\n app=app,\n ws=ws_protocol_cls,\n http=http_protocol_cls,\n lifespan=\"off\",\n port=unused_tcp_port,\n )\n async with run_server(config):\n> await websocket_session(f\"ws://127.0.0.1:{unused_tcp_port}\")\n\ntests/protocols/test_websocket.py:1219: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ntests/protocols/test_websocket.py:1201: in websocket_session\n response = await wsresponse(url)\ntests/protocols/test_websocket.py:73: in wsresponse\n return await client.get(url, headers=headers)\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpx/_client.py:1786: in get\n return await self.request(\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpx/_client.py:1559: in request\n return await self.send(request, auth=auth, follow_redirects=follow_redirects)\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpx/_client.py:1646: in send\n response = await self._send_handling_auth(\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpx/_client.py:1674: in _send_handling_auth\n response = await self._send_handling_redirects(\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpx/_client.py:1711: in _send_handling_redirects\n response = await self._send_single_request(request)\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpx/_client.py:1748: in _send_single_request\n response = await transport.handle_async_request(request)\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpx/_transports/default.py:370: in handle_async_request\n with map_httpcore_exceptions():\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/contextlib.py:158: in __exit__\n self.gen.throw(typ, value, traceback)\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n @contextlib.contextmanager\n def map_httpcore_exceptions() -> typing.Iterator[None]:\n try:\n yield\n except Exception as exc:\n mapped_exc = None\n \n for from_exc, to_exc in HTTPCORE_EXC_MAP.items():\n if not isinstance(exc, from_exc):\n continue\n # We want to map to the most specific exception we can find.\n # Eg if `exc` is an `httpcore.ReadTimeout`, we want to map to\n # `httpx.ReadTimeout`, not just `httpx.TimeoutException`.\n if mapped_exc is None or issubclass(to_exc, mapped_exc):\n mapped_exc = to_exc\n \n if mapped_exc is None: # pragma: no cover\n raise\n \n message = str(exc)\n> raise mapped_exc(message) from exc\nE httpx.RemoteProtocolError: Server disconnected without sending a response.\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/httpx/_transports/default.py:84: RemoteProtocolError\n----------------------------- Captured stderr call -----------------------------\nINFO: Started server process [1915]\nINFO: Uvicorn running on http://127.0.0.1:34651 (Press CTRL+C to quit)\nINFO: ('127.0.0.1', 33874) - \"WebSocket /\" 403\nINFO: connection rejected (403 Forbidden)\nINFO: connection closed\nINFO: Shutting down\n------------------------------ Captured log call -------------------------------\nINFO uvicorn.error:server.py:77 Started server process [1915]\nINFO uvicorn.error:server.py:219 Uvicorn running on http://127.0.0.1:34651 (Press CTRL+C to quit)\nINFO uvicorn.error:websockets_impl.py:317 ('127.0.0.1', 33874) - \"WebSocket /\" 403\nINFO uvicorn.error:server.py:229 connection rejected (403 Forbidden)\nINFO uvicorn.error:server.py:264 connection closed\nINFO uvicorn.error:server.py:265 Shutting down\n____ test_server_reject_connection_with_missing_body[websockets-httptools] _____\n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x5565a54387b0>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n> status_line = await read_line(stream)\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/http.py:120: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x5565a54387b0>>\n\n async def read_line(stream: asyncio.StreamReader) -> bytes:\n \"\"\"\n Read a single line from ``stream``.\n \n CRLF is stripped from the return value.\n \n \"\"\"\n # Security: this is bounded by the StreamReader's limit (default = 32\u00a0KiB).\n line = await stream.readline()\n # Security: this guarantees header values are small (hard-coded = 8\u00a0KiB)\n if len(line) > MAX_LINE:\n raise SecurityError(\"line too long\")\n # Not mandatory but safe - https://www.rfc-editor.org/rfc/rfc7230.html#section-3.5\n if not line.endswith(b\"\\r\\n\"):\n> raise EOFError(\"line without CRLF\")\nE EOFError: line without CRLF\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/http.py:200: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7f98409d1750>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n> status_code, reason, headers = await read_response(self.reader)\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:139: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x5565a54387b0>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n status_line = await read_line(stream)\n except EOFError as exc:\n> raise EOFError(\"connection closed while reading HTTP status line\") from exc\nE EOFError: connection closed while reading HTTP status line\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/http.py:122: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nws_protocol_cls = <class 'uvicorn.protocols.websockets.websockets_impl.WebSocketProtocol'>\nhttp_protocol_cls = <class 'uvicorn.protocols.http.httptools_impl.HttpToolsProtocol'>\nunused_tcp_port = 41033\n\n @pytest.mark.anyio\n async def test_server_reject_connection_with_missing_body(\n ws_protocol_cls: \"typing.Type[WSProtocol | WebSocketProtocol]\",\n http_protocol_cls: \"typing.Type[H11Protocol | HttpToolsProtocol]\",\n unused_tcp_port: int,\n ):\n async def app(scope, receive, send):\n assert scope[\"type\"] == \"websocket\"\n assert \"websocket.http.response\" in scope[\"extensions\"]\n \n # Pull up first recv message.\n message = await receive()\n assert message[\"type\"] == \"websocket.connect\"\n \n message = {\n \"type\": \"websocket.http.response.start\",\n \"status\": 404,\n \"headers\": [(b\"Content-Length\", b\"0\"), (b\"Content-Type\", b\"text/plain\")],\n }\n await send(message)\n # no further message\n \n async def websocket_session(url):\n with pytest.raises(websockets.exceptions.InvalidStatusCode) as exc_info:\n async with websockets.client.connect(url):\n pass # pragma: no cover\n assert exc_info.value.status_code == 404\n \n config = Config(\n app=app,\n ws=ws_protocol_cls,\n http=http_protocol_cls,\n lifespan=\"off\",\n port=unused_tcp_port,\n )\n async with run_server(config):\n> await websocket_session(f\"ws://127.0.0.1:{unused_tcp_port}\")\n\ntests/protocols/test_websocket.py:1298: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ntests/protocols/test_websocket.py:1286: in websocket_session\n async with websockets.client.connect(url):\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:629: in __aenter__\n return await self\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:647: in __await_impl_timeout__\n return await self.__await_impl__()\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:654: in __await_impl__\n await protocol.handshake(\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:319: in handshake\n status_code, response_headers = await self.read_http_response()\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7f98409d1750>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n status_code, reason, headers = await read_response(self.reader)\n except Exception as exc:\n> raise InvalidMessage(\"did not receive a valid HTTP response\") from exc\nE websockets.exceptions.InvalidMessage: did not receive a valid HTTP response\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:141: InvalidMessage\n----------------------------- Captured stderr call -----------------------------\nINFO: Started server process [1915]\nINFO: Uvicorn running on http://127.0.0.1:41033 (Press CTRL+C to quit)\nINFO: ('127.0.0.1', 36320) - \"WebSocket /\" 404\nINFO: connection rejected (404 Not Found)\nINFO: connection closed\nINFO: Shutting down\n------------------------------ Captured log call -------------------------------\nINFO uvicorn.error:server.py:77 Started server process [1915]\nINFO uvicorn.error:server.py:219 Uvicorn running on http://127.0.0.1:41033 (Press CTRL+C to quit)\nINFO uvicorn.error:websockets_impl.py:317 ('127.0.0.1', 36320) - \"WebSocket /\" 404\nINFO uvicorn.error:server.py:229 connection rejected (404 Not Found)\nINFO uvicorn.error:server.py:264 connection closed\nINFO uvicorn.error:server.py:265 Shutting down\n_______ test_server_reject_connection_with_missing_body[websockets-h11] ________\n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x5565a5438500>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n> status_line = await read_line(stream)\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/http.py:120: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x5565a5438500>>\n\n async def read_line(stream: asyncio.StreamReader) -> bytes:\n \"\"\"\n Read a single line from ``stream``.\n \n CRLF is stripped from the return value.\n \n \"\"\"\n # Security: this is bounded by the StreamReader's limit (default = 32\u00a0KiB).\n line = await stream.readline()\n # Security: this guarantees header values are small (hard-coded = 8\u00a0KiB)\n if len(line) > MAX_LINE:\n raise SecurityError(\"line too long\")\n # Not mandatory but safe - https://www.rfc-editor.org/rfc/rfc7230.html#section-3.5\n if not line.endswith(b\"\\r\\n\"):\n> raise EOFError(\"line without CRLF\")\nE EOFError: line without CRLF\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/http.py:200: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7f9840e04550>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n> status_code, reason, headers = await read_response(self.reader)\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:139: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x5565a5438500>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n status_line = await read_line(stream)\n except EOFError as exc:\n> raise EOFError(\"connection closed while reading HTTP status line\") from exc\nE EOFError: connection closed while reading HTTP status line\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/http.py:122: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nws_protocol_cls = <class 'uvicorn.protocols.websockets.websockets_impl.WebSocketProtocol'>\nhttp_protocol_cls = <class 'uvicorn.protocols.http.h11_impl.H11Protocol'>\nunused_tcp_port = 36033\n\n @pytest.mark.anyio\n async def test_server_reject_connection_with_missing_body(\n ws_protocol_cls: \"typing.Type[WSProtocol | WebSocketProtocol]\",\n http_protocol_cls: \"typing.Type[H11Protocol | HttpToolsProtocol]\",\n unused_tcp_port: int,\n ):\n async def app(scope, receive, send):\n assert scope[\"type\"] == \"websocket\"\n assert \"websocket.http.response\" in scope[\"extensions\"]\n \n # Pull up first recv message.\n message = await receive()\n assert message[\"type\"] == \"websocket.connect\"\n \n message = {\n \"type\": \"websocket.http.response.start\",\n \"status\": 404,\n \"headers\": [(b\"Content-Length\", b\"0\"), (b\"Content-Type\", b\"text/plain\")],\n }\n await send(message)\n # no further message\n \n async def websocket_session(url):\n with pytest.raises(websockets.exceptions.InvalidStatusCode) as exc_info:\n async with websockets.client.connect(url):\n pass # pragma: no cover\n assert exc_info.value.status_code == 404\n \n config = Config(\n app=app,\n ws=ws_protocol_cls,\n http=http_protocol_cls,\n lifespan=\"off\",\n port=unused_tcp_port,\n )\n async with run_server(config):\n> await websocket_session(f\"ws://127.0.0.1:{unused_tcp_port}\")\n\ntests/protocols/test_websocket.py:1298: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ntests/protocols/test_websocket.py:1286: in websocket_session\n async with websockets.client.connect(url):\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:629: in __aenter__\n return await self\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:647: in __await_impl_timeout__\n return await self.__await_impl__()\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:654: in __await_impl__\n await protocol.handshake(\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:319: in handshake\n status_code, response_headers = await self.read_http_response()\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7f9840e04550>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n status_code, reason, headers = await read_response(self.reader)\n except Exception as exc:\n> raise InvalidMessage(\"did not receive a valid HTTP response\") from exc\nE websockets.exceptions.InvalidMessage: did not receive a valid HTTP response\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:141: InvalidMessage\n----------------------------- Captured stderr call -----------------------------\nINFO: Started server process [1915]\nINFO: Uvicorn running on http://127.0.0.1:36033 (Press CTRL+C to quit)\nINFO: ('127.0.0.1', 50070) - \"WebSocket /\" 404\nINFO: connection rejected (404 Not Found)\nINFO: connection closed\nINFO: Shutting down\n------------------------------ Captured log call -------------------------------\nINFO uvicorn.error:server.py:77 Started server process [1915]\nINFO uvicorn.error:server.py:219 Uvicorn running on http://127.0.0.1:36033 (Press CTRL+C to quit)\nINFO uvicorn.error:websockets_impl.py:317 ('127.0.0.1', 50070) - \"WebSocket /\" 404\nINFO uvicorn.error:server.py:229 connection rejected (404 Not Found)\nINFO uvicorn.error:server.py:264 connection closed\nINFO uvicorn.error:server.py:265 Shutting down\n_ test_server_multiple_websocket_http_response_start_events[websockets-httptools] _\n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x5565a58897f0>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n> status_line = await read_line(stream)\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/http.py:120: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x5565a58897f0>>\n\n async def read_line(stream: asyncio.StreamReader) -> bytes:\n \"\"\"\n Read a single line from ``stream``.\n \n CRLF is stripped from the return value.\n \n \"\"\"\n # Security: this is bounded by the StreamReader's limit (default = 32\u00a0KiB).\n line = await stream.readline()\n # Security: this guarantees header values are small (hard-coded = 8\u00a0KiB)\n if len(line) > MAX_LINE:\n raise SecurityError(\"line too long\")\n # Not mandatory but safe - https://www.rfc-editor.org/rfc/rfc7230.html#section-3.5\n if not line.endswith(b\"\\r\\n\"):\n> raise EOFError(\"line without CRLF\")\nE EOFError: line without CRLF\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/http.py:200: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7f9840dc7fd0>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n> status_code, reason, headers = await read_response(self.reader)\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:139: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x5565a58897f0>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n status_line = await read_line(stream)\n except EOFError as exc:\n> raise EOFError(\"connection closed while reading HTTP status line\") from exc\nE EOFError: connection closed while reading HTTP status line\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/http.py:122: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nws_protocol_cls = <class 'uvicorn.protocols.websockets.websockets_impl.WebSocketProtocol'>\nhttp_protocol_cls = <class 'uvicorn.protocols.http.httptools_impl.HttpToolsProtocol'>\nunused_tcp_port = 57873\n\n @pytest.mark.anyio\n async def test_server_multiple_websocket_http_response_start_events(\n ws_protocol_cls: \"typing.Type[WSProtocol | WebSocketProtocol]\",\n http_protocol_cls: \"typing.Type[H11Protocol | HttpToolsProtocol]\",\n unused_tcp_port: int,\n ):\n \"\"\"\n The server should raise an exception if it sends multiple\n websocket.http.response.start events.\n \"\"\"\n exception_message: typing.Optional[str] = None\n \n async def app(scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable):\n nonlocal exception_message\n assert scope[\"type\"] == \"websocket\"\n assert \"extensions\" in scope\n assert \"websocket.http.response\" in scope[\"extensions\"]\n \n # Pull up first recv message.\n message = await receive()\n assert message[\"type\"] == \"websocket.connect\"\n \n start_event: WebSocketResponseStartEvent = {\n \"type\": \"websocket.http.response.start\",\n \"status\": 404,\n \"headers\": [(b\"Content-Length\", b\"0\"), (b\"Content-Type\", b\"text/plain\")],\n }\n await send(start_event)\n try:\n await send(start_event)\n except Exception as exc:\n exception_message = str(exc)\n \n async def websocket_session(url: str):\n with pytest.raises(websockets.exceptions.InvalidStatusCode) as exc_info:\n async with websockets.client.connect(url):\n pass\n assert exc_info.value.status_code == 404\n \n config = Config(\n app=app,\n ws=ws_protocol_cls,\n http=http_protocol_cls,\n lifespan=\"off\",\n port=unused_tcp_port,\n )\n async with run_server(config):\n> await websocket_session(f\"ws://127.0.0.1:{unused_tcp_port}\")\n\ntests/protocols/test_websocket.py:1348: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ntests/protocols/test_websocket.py:1336: in websocket_session\n async with websockets.client.connect(url):\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:629: in __aenter__\n return await self\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:647: in __await_impl_timeout__\n return await self.__await_impl__()\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:654: in __await_impl__\n await protocol.handshake(\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:319: in handshake\n status_code, response_headers = await self.read_http_response()\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7f9840dc7fd0>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n status_code, reason, headers = await read_response(self.reader)\n except Exception as exc:\n> raise InvalidMessage(\"did not receive a valid HTTP response\") from exc\nE websockets.exceptions.InvalidMessage: did not receive a valid HTTP response\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:141: InvalidMessage\n----------------------------- Captured stderr call -----------------------------\nINFO: Started server process [1915]\nINFO: Uvicorn running on http://127.0.0.1:57873 (Press CTRL+C to quit)\nINFO: ('127.0.0.1', 59494) - \"WebSocket /\" 404\nINFO: connection rejected (404 Not Found)\nINFO: connection closed\nINFO: Shutting down\n------------------------------ Captured log call -------------------------------\nINFO uvicorn.error:server.py:77 Started server process [1915]\nINFO uvicorn.error:server.py:219 Uvicorn running on http://127.0.0.1:57873 (Press CTRL+C to quit)\nINFO uvicorn.error:websockets_impl.py:317 ('127.0.0.1', 59494) - \"WebSocket /\" 404\nINFO uvicorn.error:server.py:229 connection rejected (404 Not Found)\nINFO uvicorn.error:server.py:264 connection closed\nINFO uvicorn.error:server.py:265 Shutting down\n__ test_server_multiple_websocket_http_response_start_events[websockets-h11] ___\n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x5565a58460a0>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n> status_line = await read_line(stream)\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/http.py:120: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x5565a58460a0>>\n\n async def read_line(stream: asyncio.StreamReader) -> bytes:\n \"\"\"\n Read a single line from ``stream``.\n \n CRLF is stripped from the return value.\n \n \"\"\"\n # Security: this is bounded by the StreamReader's limit (default = 32\u00a0KiB).\n line = await stream.readline()\n # Security: this guarantees header values are small (hard-coded = 8\u00a0KiB)\n if len(line) > MAX_LINE:\n raise SecurityError(\"line too long\")\n # Not mandatory but safe - https://www.rfc-editor.org/rfc/rfc7230.html#section-3.5\n if not line.endswith(b\"\\r\\n\"):\n> raise EOFError(\"line without CRLF\")\nE EOFError: line without CRLF\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/http.py:200: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7f9840e07e10>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n> status_code, reason, headers = await read_response(self.reader)\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:139: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nstream = <StreamReader eof limit=32768 transport=<TCPTransport closed=True reading=False 0x5565a58460a0>>\n\n async def read_response(stream: asyncio.StreamReader) -> Tuple[int, str, Headers]:\n \"\"\"\n Read an HTTP/1.1 response and return ``(status_code, reason, headers)``.\n \n ``reason`` and ``headers`` are expected to contain only ASCII characters.\n Other characters are represented with surrogate escapes.\n \n :func:`read_request` doesn't attempt to read the response body because\n WebSocket handshake responses don't have one. If the response contains a\n body, it may be read from ``stream`` after this coroutine returns.\n \n Args:\n stream: Input to read the response from.\n \n Raises:\n EOFError: If the connection is closed without a full HTTP response.\n SecurityError: If the response exceeds a security limit.\n ValueError: If the response isn't well formatted.\n \n \"\"\"\n # https://www.rfc-editor.org/rfc/rfc7230.html#section-3.1.2\n \n # As in read_request, parsing is simple because a fixed value is expected\n # for version, status_code is a 3-digit number, and reason can be ignored.\n \n try:\n status_line = await read_line(stream)\n except EOFError as exc:\n> raise EOFError(\"connection closed while reading HTTP status line\") from exc\nE EOFError: connection closed while reading HTTP status line\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/http.py:122: EOFError\n\nThe above exception was the direct cause of the following exception:\n\nws_protocol_cls = <class 'uvicorn.protocols.websockets.websockets_impl.WebSocketProtocol'>\nhttp_protocol_cls = <class 'uvicorn.protocols.http.h11_impl.H11Protocol'>\nunused_tcp_port = 39787\n\n @pytest.mark.anyio\n async def test_server_multiple_websocket_http_response_start_events(\n ws_protocol_cls: \"typing.Type[WSProtocol | WebSocketProtocol]\",\n http_protocol_cls: \"typing.Type[H11Protocol | HttpToolsProtocol]\",\n unused_tcp_port: int,\n ):\n \"\"\"\n The server should raise an exception if it sends multiple\n websocket.http.response.start events.\n \"\"\"\n exception_message: typing.Optional[str] = None\n \n async def app(scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable):\n nonlocal exception_message\n assert scope[\"type\"] == \"websocket\"\n assert \"extensions\" in scope\n assert \"websocket.http.response\" in scope[\"extensions\"]\n \n # Pull up first recv message.\n message = await receive()\n assert message[\"type\"] == \"websocket.connect\"\n \n start_event: WebSocketResponseStartEvent = {\n \"type\": \"websocket.http.response.start\",\n \"status\": 404,\n \"headers\": [(b\"Content-Length\", b\"0\"), (b\"Content-Type\", b\"text/plain\")],\n }\n await send(start_event)\n try:\n await send(start_event)\n except Exception as exc:\n exception_message = str(exc)\n \n async def websocket_session(url: str):\n with pytest.raises(websockets.exceptions.InvalidStatusCode) as exc_info:\n async with websockets.client.connect(url):\n pass\n assert exc_info.value.status_code == 404\n \n config = Config(\n app=app,\n ws=ws_protocol_cls,\n http=http_protocol_cls,\n lifespan=\"off\",\n port=unused_tcp_port,\n )\n async with run_server(config):\n> await websocket_session(f\"ws://127.0.0.1:{unused_tcp_port}\")\n\ntests/protocols/test_websocket.py:1348: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \ntests/protocols/test_websocket.py:1336: in websocket_session\n async with websockets.client.connect(url):\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:629: in __aenter__\n return await self\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:647: in __await_impl_timeout__\n return await self.__await_impl__()\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:654: in __await_impl__\n await protocol.handshake(\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:319: in handshake\n status_code, response_headers = await self.read_http_response()\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <websockets.legacy.client.WebSocketClientProtocol object at 0x7f9840e07e10>\n\n async def read_http_response(self) -> Tuple[int, Headers]:\n \"\"\"\n Read status line and headers from the HTTP response.\n \n If the response contains a body, it may be read from ``self.reader``\n after this coroutine returns.\n \n Raises:\n InvalidMessage: If the HTTP message is malformed or isn't an\n HTTP/1.1 GET response.\n \n \"\"\"\n try:\n status_code, reason, headers = await read_response(self.reader)\n except Exception as exc:\n> raise InvalidMessage(\"did not receive a valid HTTP response\") from exc\nE websockets.exceptions.InvalidMessage: did not receive a valid HTTP response\n\n/opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/websockets/legacy/client.py:141: InvalidMessage\n----------------------------- Captured stderr call -----------------------------\nINFO: Started server process [1915]\nINFO: Uvicorn running on http://127.0.0.1:39787 (Press CTRL+C to quit)\nINFO: ('127.0.0.1', 43558) - \"WebSocket /\" 404\nINFO: connection rejected (404 Not Found)\nINFO: connection closed\nINFO: Shutting down\n------------------------------ Captured log call -------------------------------\nINFO uvicorn.error:server.py:77 Started server process [1915]\nINFO uvicorn.error:server.py:219 Uvicorn running on http://127.0.0.1:39787 (Press CTRL+C to quit)\nINFO uvicorn.error:websockets_impl.py:317 ('127.0.0.1', 43558) - \"WebSocket /\" 404\nINFO uvicorn.error:server.py:229 connection rejected (404 Not Found)\nINFO uvicorn.error:server.py:264 connection closed\nINFO uvicorn.error:server.py:265 Shutting down\n=================== 6 failed, 559 passed in 66.08s (0:01:06) ===================\n##[error]Process completed with exit code 1.\n"}], "diff": "diff --git a/uvicorn/protocols/websockets/websockets_impl.py b/uvicorn/protocols/websockets/websockets_impl.py\nindex 44994b4..57350f6 100644\n--- a/uvicorn/protocols/websockets/websockets_impl.py\n+++ b/uvicorn/protocols/websockets/websockets_impl.py\n@@ -271,11 +271,12 @@ class WebSocketProtocol(WebSocketServerProtocol):\n msg = \"ASGI callable returned without sending handshake.\"\n self.logger.error(msg)\n self.send_500_response()\n+ self.transport.close()\n elif result is not None:\n msg = \"ASGI callable should return None, but returned '%s'.\"\n self.logger.error(msg, result)\n await self.handshake_completed_event.wait()\n- self.transport.close()\n+ self.transport.close()\n \n async def asgi_send(self, message: \"ASGISendEvent\") -> None:\n message_type = message[\"type\"]\n", "difficulty": 2, "changed_files": ["uvicorn/protocols/websockets/websockets_impl.py"], "commit_link": "https://github.com/encode/uvicorn/tree/0b93d2da3b721c80dcb6a2993a23876a97498dd5"}