Skip to content

#1178 Support for route parameters in WebSocket onaccept handlers - #1224

Open
jwolak wants to merge 1 commit into
CrowCpp:masterfrom
jwolak:feature/issue_1178_websocket-onaccept-route-params
Open

#1178 Support for route parameters in WebSocket onaccept handlers#1224
jwolak wants to merge 1 commit into
CrowCpp:masterfrom
jwolak:feature/issue_1178_websocket-onaccept-route-params

Conversation

@jwolak

@jwolak jwolak commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Refers to #1178

Add support parameterized routes like:
/ws/<int>
/ws/<string>
/ws/<path>
and pass the parsed values directly into the onaccept callback, e.g.:

CROW_WEBSOCKET_ROUTE(app, "/ws/<int>")
  .onaccept([](const crow::request&, std::optional<crow::response>&, void**, int64_t id) {
      // id == parsed route parameter
  });

This makes WebSocket route logic consistent with the rest of Crow’s routing system and enables request-specific validation or connection setup based on URL parameters.

The change also supports bool-returning onaccept handlers, where returning false rejects the upgrade with a 400 response, and includes unit tests covering int, uint, double, string, path, and rejection cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant