Add selective WebSocket message compression - #1172
Merged
Merged
Conversation
Contributor
Author
|
This is needed for Play so we can implement a threshold: |
pjfanning
reviewed
Jul 23, 2026
Contributor
Author
|
any chance this gets merged within the next 5 hours so it makes it into the next nightly (so tomorrow I can build against that in Play)? (no pressure however, just checking) |
Member
|
@mkurz could you fix the merge conflicts and I'll merge. |
mkurz
force-pushed
the
websocket-per-message-compression
branch
from
July 23, 2026 21:39
1b19c3a to
7939ace
Compare
Contributor
Author
|
Thanks! |
Member
|
2.0.0-M1+205-35174606-SNAPSHOT is published |
This was referenced Jul 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds server-side per-message compression selection when
permessage-deflatehas been negotiated.Applications can now decide independently for every outbound text or binary message whether it should be compressed. This supports policies such as skipping sensitive, already-compressed, or small messages while retaining compression for the rest of the WebSocket connection.
API
The Scala API accepts a
Message => Booleanselector, while the Java API accepts aPredicate<Message>.Selector overloads are available for:
WebSocketUpgrade.handleMessagesWebSocketUpgrade.handleMessagesWithSinkSourcehandleWebSocketMessageshandleWebSocketMessagesForProtocolhandleWebSocketMessagesForOptionalProtocolThe internal low-level frame API additionally accepts a
FrameStart => Booleanselector.Behavior
permessage-deflatewas negotiated.Returning
trueselects compression for the message. It does not enable or negotiate compression by itself.Implementation
The high-level message API evaluates the selector before rendering and carries the result on the initial frame for the compression stage.
The low-level frame API evaluates its selector directly for the initial text or binary frame. The compression stage retains that choice until the final continuation frame.
This is similar to Netty's per-message WebSocket extension filter while using Pekko HTTP's existing streaming frame pipeline.
Compatibility
All existing overloads and internal entry points remain available and delegate to the previous compress-all behavior.
The new Scala trait methods are concrete delegating methods, so existing implementations do not need to implement them.
Testing
Coverage includes:
Validation performed with:
References