-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Expose Websocket close frame when closing from server side #2964
Comments
You can implement this yourself by sending a close message to the WebSocket. This issue also caused me to discover that Axum’s current I think I’ll make a PR to remove |
Yeah I did discover that just sending CloseFrame message manually closes the connection. but sending a CloseMessage doesnt take ownership of socket so it's not apparent that it'll also shutdown the websocket connection. Could be just lack of knowledge on my part. |
So this is actually a good thing. The way the WebSocket closing protocol is supposed to work is that:
If close methods take ownership, this protocol is impossible to implement correctly as peer A would not receive the remaining frames from peer B. |
Feature Request
If I understand correctly, currently we cannot set close reason and code when closing websocket from server side, axum is already exposing
CloseCode
andCloseFrame
for close msg from client side, but we cannot pass it when closing from server.Motivation
For me i want to reject some websocket connection but websocket spec doest let js get http status code and msg when connect to websocket and failing. Recommended method to do so is to accept connection and immediately close with reason according to https://stackoverflow.com/a/50685387.
Currently I cannot do this. close method does not take any parameters.
Proposal
To maintain backward compatibility we can expose another method,
close_with_msg(msg:CloseFrame)
which will pass it to tungstenite.Alternatives
maybe we can do
socket.send(axum::extract::ws::Message::Close(()))
before callingsocket.close()
but this seems weird to be, I dont know if sending close frame is also closing connection or not.The text was updated successfully, but these errors were encountered: