Skip to content
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 to specify the max websockets frame size when using the upgrader. #315

Merged
merged 5 commits into from
Apr 16, 2018

Conversation

normanmaurer
Copy link
Member

Motivation:

At the moment its not possible to adjust the max websockets frame size when using the upgrader while its possible when directly use the WebSocketFrameDecoder.

Modifications:

Allow to specify max frame size via an init argument (with default value).

Result:

More flexible way to use the upgrader.

Motivation:

At the moment its not possible to adjust the max websockets frame size when using the upgrader while its possible when directly use the WebSocketFrameDecoder.

Modifications:

Allow to specify max frame size via an init argument (with default value).

Result:

More flexible way to use the upgrader.
@normanmaurer normanmaurer requested review from Lukasa and weissi April 16, 2018 06:06
@normanmaurer
Copy link
Member Author

also @vlm

Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind writing a test for me please?

@normanmaurer normanmaurer force-pushed the websocket_upgrade_frame_size branch from be08eaa to aee563f Compare April 16, 2018 09:57
@normanmaurer
Copy link
Member Author

@Lukasa done

@@ -221,7 +221,7 @@ public final class WebSocketFrameDecoder: ByteToMessageDecoder {
public var cumulationBuffer: ByteBuffer? = nil

/// The maximum frame size the decoder is willing to tolerate from the remote peer.
private let maxFrameSize: Int
public let maxFrameSize: Int
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can also keep this internal if we like

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my vote would go to let's keep it internal :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I think we should keep it internal too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's always easier to make things more public than to make them less public.

public init(shouldUpgrade: @escaping (HTTPRequestHead) -> HTTPHeaders?,
upgradePipelineHandler: @escaping (Channel, HTTPRequestHead) -> EventLoopFuture<Void>) {
upgradePipelineHandler: @escaping (Channel, HTTPRequestHead) -> EventLoopFuture<Void>, maxFrameSize: Int = 1 << 14) {
precondition(maxFrameSize <= UInt32.max, "invalid overlarge max frame size")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you're already preconditioning here, mind checking it's positive too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any point in this precondition? I think it just duplicates logic that exists in the web socket frame decoder.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lukasa imho its better to fail fast... WDYT ?

@@ -221,7 +221,7 @@ public final class WebSocketFrameDecoder: ByteToMessageDecoder {
public var cumulationBuffer: ByteBuffer? = nil

/// The maximum frame size the decoder is willing to tolerate from the remote peer.
private let maxFrameSize: Int
public let maxFrameSize: Int
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I think we should keep it internal too.

@@ -221,7 +221,7 @@ public final class WebSocketFrameDecoder: ByteToMessageDecoder {
public var cumulationBuffer: ByteBuffer? = nil

/// The maximum frame size the decoder is willing to tolerate from the remote peer.
private let maxFrameSize: Int
public let maxFrameSize: Int
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's always easier to make things more public than to make them less public.

public init(shouldUpgrade: @escaping (HTTPRequestHead) -> HTTPHeaders?,
upgradePipelineHandler: @escaping (Channel, HTTPRequestHead) -> EventLoopFuture<Void>) {
upgradePipelineHandler: @escaping (Channel, HTTPRequestHead) -> EventLoopFuture<Void>, maxFrameSize: Int = 1 << 14) {
precondition(maxFrameSize <= UInt32.max, "invalid overlarge max frame size")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any point in this precondition? I think it just duplicates logic that exists in the web socket frame decoder.

public init(shouldUpgrade: @escaping (HTTPRequestHead) -> HTTPHeaders?,
upgradePipelineHandler: @escaping (Channel, HTTPRequestHead) -> EventLoopFuture<Void>) {
upgradePipelineHandler: @escaping (Channel, HTTPRequestHead) -> EventLoopFuture<Void>, maxFrameSize: Int = 1 << 14) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I recommend that instead of making this change you just add a new constructor that this one calls, with maxFrameSize earlier in the argument list? Trailing closures are really nice, and it's a shame to lose them.

Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely meant request changes, sorry.

Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, merge when ready.

Copy link
Member

@weissi weissi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice one thanks

self.shouldUpgrade = shouldUpgrade
self.upgradePipelineHandler = upgradePipelineHandler
self.maxFrameSize = maxFrameSize
}
Copy link
Contributor

@vlm vlm Apr 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, what is the motivation for providing two public constructors rather than a constructor with the default value?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vlm Short answer is "to preserve the trailing closure".

@@ -221,7 +221,7 @@ public final class WebSocketFrameDecoder: ByteToMessageDecoder {
public var cumulationBuffer: ByteBuffer? = nil

/// The maximum frame size the decoder is willing to tolerate from the remote peer.
private let maxFrameSize: Int
/* private but tests */ let maxFrameSize: Int
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it make even more sense to test behavior (e.g., ability and inability to transfer more than the limit when the limit is appropriately changed) rather than checking whether we set the maxFrameSize. It'll have a nice side effect of eliminating this comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vlm I will add more tests as a followup to test max frame size handling. But I think this is ok to test what the change did.

@normanmaurer normanmaurer merged commit 178dd76 into apple:master Apr 16, 2018
@normanmaurer normanmaurer deleted the websocket_upgrade_frame_size branch April 16, 2018 18:13
@normanmaurer normanmaurer added this to the 1.5.0 milestone Apr 16, 2018
@Lukasa Lukasa added the 🆕 semver/minor Adds new public API. label Apr 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants