-
Notifications
You must be signed in to change notification settings - Fork 654
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
Fix WebSocketProtocolErrorHandler sending the close frame with appropriate masking key #3040
Conversation
Given previously a masking key wasn't added shouldn't the default continue to be that. Also adding a parameter to a function is considered a breaking change, even if it has a default value. You need to add a new function which sets the |
Hi @adam-fowler, thanks for the review. I addressed your comments in the most recent version. Please let me know if everything looks good now or if there’s anything else you’d like me to adjust. Thanks again! |
Instead of having a mutable isServer member variable. You could have two initializers. The original and a new one which takes a isServer parameter. NIO folks will have last say on this though. |
I like Adam's suggestion of using a |
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.
Generally looks good, just a quick note!
Thanks @Lukasa for the review! I updated the PR to address your comments. Could you please review whenever you are available? Appreciate it! |
Hi @Lukasa, whenever you are available, can you please re-review this PR? I modified it according to your comments. Let me know if there is any change I need to make. Thanks for your time in advance! |
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.
Looks great, thanks @johnnzhou!
Enhance
WebSocketProtocolErrorHandler
to correctly add masking key for client/server.Motivation:
In
NIOWebSocket
, the automatic error handling provided byWebSocketProtocolErrorHandler
offers a convenient way for both clients and servers to handle protocol-level errors. However, theWebSocketFrame
used inWebSocketProtocolErrorHandler
does not fully adhere to the RFC 6455 standard. Specifically, as per RFC 6455 Section 5.1, a client must mask all frames it sends to the server, while a server must not mask any frames it sends to the client. This PR addressed this discrepancy to ensure compliance with the WebSocket protocol.Modifications:
In the
WebSocketProtocolErrorHandler
initializer, the user can specify whether the handler is used for a WebSocket client or server. Within theerrorCaught
method, theWebSocketFrame
will include a maskingKey if the handler is used by a client, or nil if it is used by a server.Additionally, the
@unchecked
annotation is removed fromNIOWebSocketServerUpgrader
since the project is now using swift 5.9 toolchain.Result:
The
WebSocketProtocolErrorHandler
is more robust and can correctly close the connection is error occurs.