diff --git a/sanic/server.py b/sanic/server.py index 2e27d80b..07b755ed 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -14,7 +14,7 @@ from ipaddress import ip_address from signal import SIG_IGN, SIGINT, SIGTERM, Signals from signal import signal as signal_func from time import time -from typing import Type +from typing import Dict, Type, Union from httptools import HttpRequestParser # type: ignore from httptools.parser.errors import HttpParserError # type: ignore @@ -955,15 +955,15 @@ def serve( def _build_protocol_kwargs( protocol: Type[HttpProtocol], config: Config -) -> dict: - if hasattr(protocol, "websocket_timeout"): +) -> Dict[str, Union[int, float]]: + if hasattr(protocol, "websocket_handshake"): return { - "max_size": config.WEBSOCKET_MAX_SIZE, - "max_queue": config.WEBSOCKET_MAX_QUEUE, - "read_limit": config.WEBSOCKET_READ_LIMIT, - "write_limit": config.WEBSOCKET_WRITE_LIMIT, - "ping_timeout": config.WEBSOCKET_PING_TIMEOUT, - "ping_interval": config.WEBSOCKET_PING_INTERVAL, + "websocket_max_size": config.WEBSOCKET_MAX_SIZE, + "websocket_max_queue": config.WEBSOCKET_MAX_QUEUE, + "websocket_read_limit": config.WEBSOCKET_READ_LIMIT, + "websocket_write_limit": config.WEBSOCKET_WRITE_LIMIT, + "websocket_ping_timeout": config.WEBSOCKET_PING_TIMEOUT, + "websocket_ping_interval": config.WEBSOCKET_PING_INTERVAL, } return {} diff --git a/tests/test_app.py b/tests/test_app.py index 5a7afa59..dab46061 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -170,12 +170,20 @@ def test_app_websocket_parameters(websocket_protocol_mock, app): websocket_protocol_call_args = websocket_protocol_mock.call_args ws_kwargs = websocket_protocol_call_args[1] - assert ws_kwargs["max_size"] == app.config.WEBSOCKET_MAX_SIZE - assert ws_kwargs["max_queue"] == app.config.WEBSOCKET_MAX_QUEUE - assert ws_kwargs["read_limit"] == app.config.WEBSOCKET_READ_LIMIT - assert ws_kwargs["write_limit"] == app.config.WEBSOCKET_WRITE_LIMIT - assert ws_kwargs["ping_timeout"] == app.config.WEBSOCKET_PING_TIMEOUT - assert ws_kwargs["ping_interval"] == app.config.WEBSOCKET_PING_INTERVAL + assert ws_kwargs["websocket_max_size"] == app.config.WEBSOCKET_MAX_SIZE + assert ws_kwargs["websocket_max_queue"] == app.config.WEBSOCKET_MAX_QUEUE + assert ws_kwargs["websocket_read_limit"] == app.config.WEBSOCKET_READ_LIMIT + assert ( + ws_kwargs["websocket_write_limit"] == app.config.WEBSOCKET_WRITE_LIMIT + ) + assert ( + ws_kwargs["websocket_ping_timeout"] + == app.config.WEBSOCKET_PING_TIMEOUT + ) + assert ( + ws_kwargs["websocket_ping_interval"] + == app.config.WEBSOCKET_PING_INTERVAL + ) def test_handle_request_with_nested_exception(app, monkeypatch):