-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net: websocket: pass request context to callback #83597
net: websocket: pass request context to callback #83597
Conversation
e0df52b
to
2229c90
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems shell_websocket.h
needs an update too (shell_websocket_setup
declaration), looks good otherwise, thanks.
Passing HTTP upgrade request context to the user callback allows the user to decide whether to accept or reject the websocket connection based on the HTTP headers in the request. The primary reason for this is to enable authentication of the websocket connection (e.g. via cookies or Authorization header). Signed-off-by: Matt Rodgers <[email protected]>
Update HTTP server documentation and migration guide to account for added request_ctx parameter to the http_resource_websocket_cb_t callback. Signed-off-by: Matt Rodgers <[email protected]>
2229c90
to
15f48a3
Compare
Good spot, updated this and also removed the |
I don'tt think they're needed either, probably just some copy-paste leftover. |
When upgrading an HTTP1 connection to a websocket, pass the HTTP request context associated with the upgrade request to the user callback.
This allows the user callback to access URL query parameters and HTTP headers. The main motivation behind this is to allow for authentication via the headers before the application decides whether to accept or reject the websocket connection, but it could also be used to provide any other context needed on opening the connection (e.g.
Sec-WebSocket-Protocol
header).