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
Allow WebSocket maxFrameSize to be configured #2195
Conversation
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.
@bridger Thanks for creating the issue, and a huge thanks for creating a PR to back it up. Really cool 👍
I think the API design could be more future-proof if we introduce a small change elsewhere.
I like the idea of returning a route that can be configured. I’d be happy to make that change if that’s preferred. I’m new to Vapor so I wasn’t sure about existing practices to follow. Sent with GitHawk |
We're in beta stages, so for now these changes are in a good spot for consideration. |
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.
+1 to adding this as a parameter. I do think it would be nice to be able to change the default maxFrameSize for all web socket connections as well, but that could be a separate PR. Something like:
app.webSocket.maxFrameSize = 1<<20
b7d21d0
to
74ffd45
Compare
To support that case, I changed the parameter to be optional. Now the default (1<<14) is an internal detail. When we add an Application-level default, like |
74ffd45
to
900bca0
Compare
900bca0
to
fa1a69f
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.
LGTM. @tanner0101 could you give this another pass too? 😄
@@ -2,11 +2,12 @@ extension RoutesBuilder { | |||
@discardableResult | |||
public func webSocket( | |||
_ path: PathComponent..., | |||
maxFrameSize: Int? = nil, |
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.
As a user, passing app.webSocket(maxFrameSize: nil) { ... }
might make me think I'm disabling max frame size here. Maybe an enum instead would better express this?
enum WebSocketMaxFrameSize {
case default
case override(Int)
}
extension WebSocketMaxFrameSize: ExpressibleByIntegerLiteral {
init(integerValue: Int) {
self = .override(integerValue)
}
}
We could re-use this enum on the top-level config as well.
This may be overly pedantic though and perhaps a doc block explaining the behavior would be sufficient. What are your thoughts?
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.
The enum is a good idea! I just updated the PR to use the enum.
Can this be merged? |
Apologies. There was an update to the PR that was waiting for me. I just made the change so I think it is good to merge. |
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!
These changes are now available in 4.0.0-rc.3.4 |
* Allow WebSocket maxFrameSize to be configured. * Change maxFrameSize to an enum instead of optional.
* Remove double quotes from cooke value (vapor#2215) * remove double quotes from cookie value * naming * naming * Expose initializer of Validator (vapor#2232) vapor#2231 Co-authored-by: seeppp <jonas.schoch@naptics.ch> * Allow WebSocket maxFrameSize to be configured (vapor#2195) * Allow WebSocket maxFrameSize to be configured. * Change maxFrameSize to an enum instead of optional. Co-authored-by: Tanner <tannernelson@gmail.com> Co-authored-by: Seeppp <jonas.schoch@icloud.com> Co-authored-by: seeppp <jonas.schoch@naptics.ch> Co-authored-by: Bridger Maxwell <bridger.maxwell@gmail.com>
* Remove double quotes from cooke value (vapor#2215) * remove double quotes from cookie value * naming * naming * Expose initializer of Validator (vapor#2232) vapor#2231 Co-authored-by: seeppp <jonas.schoch@naptics.ch> * Allow WebSocket maxFrameSize to be configured (vapor#2195) * Allow WebSocket maxFrameSize to be configured. * Change maxFrameSize to an enum instead of optional. * Implement `.hex`, `hexEncodedString()`, and `hexEncodedBytes()` on Sequence instead of restricting them to Collection. (vapor#2249) - Make `hexEncodedBytes()` public, why wouldn't it be? - Specialize `hexEncodedBytes()` on `Collection` to use a (theoretically) more efficient method. It's probably a completely unmeasurable difference in practice. - Add unit test to make sure it works on `Sequence`s. Co-authored-by: Tanner <tannernelson@gmail.com> Co-authored-by: Seeppp <jonas.schoch@icloud.com> Co-authored-by: seeppp <jonas.schoch@naptics.ch> Co-authored-by: Bridger Maxwell <bridger.maxwell@gmail.com> Co-authored-by: Gwynne Raskind <gwynne@darkrainfall.org>
* Remove double quotes from cooke value (vapor#2215) * remove double quotes from cookie value * naming * naming * Expose initializer of Validator (vapor#2232) vapor#2231 Co-authored-by: seeppp <jonas.schoch@naptics.ch> * Allow WebSocket maxFrameSize to be configured (vapor#2195) * Allow WebSocket maxFrameSize to be configured. * Change maxFrameSize to an enum instead of optional. * Implement `.hex`, `hexEncodedString()`, and `hexEncodedBytes()` on Sequence instead of restricting them to Collection. (vapor#2249) - Make `hexEncodedBytes()` public, why wouldn't it be? - Specialize `hexEncodedBytes()` on `Collection` to use a (theoretically) more efficient method. It's probably a completely unmeasurable difference in practice. - Add unit test to make sure it works on `Sequence`s. * close mode output keep-alive (vapor#2257) * fix body stream leak (vapor#2258) Co-authored-by: Tanner <tannernelson@gmail.com> Co-authored-by: Seeppp <jonas.schoch@icloud.com> Co-authored-by: seeppp <jonas.schoch@naptics.ch> Co-authored-by: Bridger Maxwell <bridger.maxwell@gmail.com> Co-authored-by: Gwynne Raskind <gwynne@darkrainfall.org>
* Remove double quotes from cooke value (vapor#2215) * remove double quotes from cookie value * naming * naming * Expose initializer of Validator (vapor#2232) vapor#2231 Co-authored-by: seeppp <jonas.schoch@naptics.ch> * Allow WebSocket maxFrameSize to be configured (vapor#2195) * Allow WebSocket maxFrameSize to be configured. * Change maxFrameSize to an enum instead of optional. * Implement `.hex`, `hexEncodedString()`, and `hexEncodedBytes()` on Sequence instead of restricting them to Collection. (vapor#2249) - Make `hexEncodedBytes()` public, why wouldn't it be? - Specialize `hexEncodedBytes()` on `Collection` to use a (theoretically) more efficient method. It's probably a completely unmeasurable difference in practice. - Add unit test to make sure it works on `Sequence`s. * close mode output keep-alive (vapor#2257) * fix body stream leak (vapor#2258) Co-authored-by: Tanner <tannernelson@gmail.com> Co-authored-by: Seeppp <jonas.schoch@icloud.com> Co-authored-by: seeppp <jonas.schoch@naptics.ch> Co-authored-by: Bridger Maxwell <bridger.maxwell@gmail.com> Co-authored-by: Gwynne Raskind <gwynne@darkrainfall.org>
The maximum frame size of an incoming WebSocket packet can be configured. This fixes issues for apps that were running into the limit (#2195, fixes #2194).