Skip to content

[Feature Request] Support path parameters injection in CROW_WEBSOCKET_ROUTE's onaccept handler #1178

Description

@zxq89

Current Behavior:
Currently, CROW_WEBSOCKET_ROUTE only supports a fixed signature for the onaccept handler:
onaccept(const crow::request&, std::optionalcrow::response&, void**)
Even if the route is defined with path parameters (e.g., /ws/), these parameters cannot be automatically injected into the handler arguments, unlike regular HTTP routes.
Not only is parameter injection missing in onaccept, but there is currently no way easily to retrieve the captured path parameters (e.g., from or ) at the WebSocket lifecycle.

Expected Behavior:
It would be highly beneficial if onaccept could support variadic arguments corresponding to the route parameters, for example:
CROW_WEBSOCKET_ROUTE(app, "/ws/<int>") .onaccept([](const crow::request &req, std::optional<crow::response> &res, void** userdata, int id) { // 'id' should be automatically parsed and injected });

Actual Behavior:
// This fails to compile with "no matching function for call to ...." CROW_WEBSOCKET_ROUTE(app, "/ws/<int>") .onaccept([](const crow::request& req, std::optional<crow::response>& res, void** userdata, int id) { // ... });

Environment:
Crow version: 1.3.2
Platform: ARM Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureCode based project improvement

    Fields

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions