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 ping handler to be set on ServerWebScoket #4794

Closed
trevorurquhart opened this issue Jul 26, 2023 · 3 comments
Closed

Allow ping handler to be set on ServerWebScoket #4794

trevorurquhart opened this issue Jul 26, 2023 · 3 comments
Assignees
Milestone

Comments

@trevorurquhart
Copy link

Describe the feature

Allow a ping handler to be specified on a ServerWebSocket (similar to pongHandler)

Use cases

Currently the ServerWebSocket responds to a ping with a pong:

// Echo back the content of the PING frame as PONG frame as specified in RFC 6455 Section 5.5.2
conn.writeToChannel(new PongWebSocketFrame(frame.getBinaryData().copy()));

We've had a use case where a user (either inadvertently or deliberately) flooded our websockets with 1000s of pings/sec. It would be nice to be able to monitor the number of pings a client web socket is sending.

We can get hold of this information if we add a framehandler to the websocket. The only issue with that is if you want to specify a text/binary message handler, the frame handler is overridden.

Contribution

Happy to supply a PR if required.

@vietj
Copy link
Member

vietj commented Jul 27, 2023

I think we could check in the frameHandler(...) method if the current frame handler is not null and is an instance of FrameAggregator and swap it to preserve the current frame handler. PR is welcome @trevorurquhart

@vietj vietj added this to the 4.4.5 milestone Jul 27, 2023
@trevorurquhart
Copy link
Author

Apologies, but I'm not totally following. Wouldn't I still lose my frame handler with this:

serverWebSocket
.frameHandler(myFrameHandler)
.textMessageHandler(myTextHandler) //Replaces my frame handler with FrameAggregator

The other issue with using a frame handler to monitor pings is that I have to re-implement FrameAggregator and attach text/binary handlers to my implementation.

Is there something I'm missing which makes this problematic?:

serverWebSocket
.textMessageHandler(myTextHandler)
.pingHandler(myPingHandler)

vietj added a commit that referenced this issue Aug 4, 2023
…e binary/text frames, this overrides a frame handler that could be set to handle frames in addition of processing them.

The implementation has been modified so that the frame aggregator for binary/text frames has its own handler, the frame aggregator and the frame handler are both notified with incoming frames.

fixes #4794
@vietj vietj self-assigned this Aug 4, 2023
vietj added a commit that referenced this issue Aug 5, 2023
…e binary/text frames, this overrides a frame handler that could be set to handle frames in addition of processing them.

The implementation has been modified so that the frame aggregator for binary/text frames has its own handler, the frame aggregator and the frame handler are both notified with incoming frames.

fixes #4794
@vietj
Copy link
Member

vietj commented Aug 5, 2023

Actually it looks simpler to simply have a field FrameAggregator in addition of the frameHandler : #4799

@vietj vietj closed this as completed in e1d1244 Aug 7, 2023
vietj added a commit that referenced this issue Aug 7, 2023
…e binary/text frames, this overrides a frame handler that could be set to handle frames in addition of processing them.

The implementation has been modified so that the frame aggregator for binary/text frames has its own handler, the frame aggregator and the frame handler are both notified with incoming frames.

fixes #4794
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants