self.path = path
self.endpoint = endpoint
self.name = get_name(endpoint) if name is None else name
- self.dependant = get_dependant(path=path, call=self.endpoint)
+ self.path_regex, self.path_format, self.param_convertors = compile_path(path)
+ self.dependant = get_dependant(path=self.path_format, call=self.endpoint)
self.app = websocket_session(
get_websocket_app(
dependant=self.dependant,
dependency_overrides_provider=dependency_overrides_provider,
)
)
- self.path_regex, self.path_format, self.param_convertors = compile_path(path)
def matches(self, scope: Scope) -> Tuple[Match, Scope]:
match, child_scope = super().matches(scope)
await websocket.close()
+@router.websocket("/router/{pathparam:path}")
+async def routerindexparams(websocket: WebSocket, pathparam: str, queryparam: str):
+ await websocket.accept()
+ await websocket.send_text(pathparam)
+ await websocket.send_text(queryparam)
+ await websocket.close()
+
+
async def ws_dependency():
return "Socket Dependency"
app.dependency_overrides[ws_dependency] = lambda: "Override"
with client.websocket_connect("/router-ws-depends/") as websocket:
assert websocket.receive_text() == "Override"
+
+
+def test_router_with_params():
+ client = TestClient(app)
+ with client.websocket_connect(
+ "/router/path/to/file?queryparam=a_query_param"
+ ) as websocket:
+ data = websocket.receive_text()
+ assert data == "path/to/file"
+ data = websocket.receive_text()
+ assert data == "a_query_param"