diff --git a/sanic/app.py b/sanic/app.py index f5bfbccf..0e055a23 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -462,7 +462,13 @@ class Sanic: # Decorator def websocket( - self, uri, host=None, strict_slashes=None, subprotocols=None, name=None + self, + uri, + host=None, + strict_slashes=None, + subprotocols=None, + version=None, + name=None, ): """ Decorate a function to be registered as a websocket route @@ -536,6 +542,7 @@ class Sanic: methods=frozenset({"GET"}), host=host, strict_slashes=strict_slashes, + version=version, name=name, ) ) @@ -550,6 +557,7 @@ class Sanic: host=None, strict_slashes=None, subprotocols=None, + version=None, name=None, ): """ @@ -577,6 +585,7 @@ class Sanic: host=host, strict_slashes=strict_slashes, subprotocols=subprotocols, + version=version, name=name, )(handler) diff --git a/tests/test_routes.py b/tests/test_routes.py index dae90a74..522e238f 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -531,6 +531,19 @@ def test_add_webscoket_route(app, strict_slashes): assert ev.is_set() +def test_add_webscoket_route_with_version(app): + ev = asyncio.Event() + + async def handler(request, ws): + assert ws.subprotocol is None + ev.set() + + app.add_websocket_route(handler, "/ws", version=1) + request, response = app.test_client.websocket("/v1/ws") + assert response.opened is True + assert ev.is_set() + + def test_route_duplicate(app): with pytest.raises(RouteExists):