diff --git a/src/websockets/legacy/server.py b/src/websockets/legacy/server.py index c9b32c41..36516c2d 100644 --- a/src/websockets/legacy/server.py +++ b/src/websockets/legacy/server.py @@ -217,6 +217,7 @@ async def handler(self) -> None: ), ) + status = http.HTTPStatus(status) headers.setdefault("Date", email.utils.formatdate(usegmt=True)) if self.server_header is not None: headers.setdefault("Server", self.server_header) diff --git a/tests/legacy/test_client_server.py b/tests/legacy/test_client_server.py index c49d91b7..2e464711 100644 --- a/tests/legacy/test_client_server.py +++ b/tests/legacy/test_client_server.py @@ -543,6 +543,17 @@ def test_process_request_override(self): with contextlib.closing(response): self.assertEqual(response.code, 200) + class ProcessRequestOKServerProtocolNumeric(WebSocketServerProtocol): + async def process_request(self, path, request_headers): + return 200, [], b"OK\n" + + @with_server(create_protocol=ProcessRequestOKServerProtocolNumeric) + def test_numeric_response_code(self): + response = self.loop.run_until_complete(self.make_http_request("/")) + + with contextlib.closing(response): + self.assertEqual(response.code, 200) + class LegacyProcessRequestOKServerProtocol(WebSocketServerProtocol): def process_request(self, path, request_headers): return http.HTTPStatus.OK, [], b"OK\n"