Skip to content

Add permessage-deflate support#1

Closed
akonradi-signal wants to merge 13 commits intomasterfrom
akonradi/deflate
Closed

Add permessage-deflate support#1
akonradi-signal wants to merge 13 commits intomasterfrom
akonradi/deflate

Conversation

@akonradi-signal
Copy link

Add support for the "permessage-deflate" websocket protocol extension as specified by RFC 7692. This is based off of snapview#426 but adds

  • separation between header parsing and negotiation logic
  • support for the client/server max window bits parameters
  • cleaner separation of feature-guarded bits for maintainability
  • additional unit testing

akonradi-signal and others added 13 commits September 12, 2025 13:22
* Box Error::Http

Reduce Error size 136 -> 56

* Box Error::WriteBufferFull

Reduce Error size 56 -> 40

* Box ProtocolError::InvalidHeader, TlsError::Native, TlsError::Rustls

Reduce ProtocolError size 40 -> 16
Reduce TlsError size 64 -> 16
Reduce Error size 40/64 -> 32

* Update changelog

* Make the code worse so users can use old rustc from 2022
Add types for the Sec-WebSocket-Extensions header, as described by RFC
6455 Section 11.3.2, and the constituent parts. Add parsing and
serialization routines.

Based on work by Benjamin Swart <[email protected]>.
Add parsing and client/server parameter negotiation for the permessage-deflate
extension from the Sec-WebSocket-Extensions header according to RFC 7692.

Based on work by Benjamin Swart <[email protected]>.
Add a DeflateContext that can be used to compress and decompress the payloads
of a single connection. Delegate to the flate2 library for the actual algorithm.

Based on work by Benjamin Swart <[email protected]>
This will let us include it in the ProtocolError hierarchy.
Add types representing the configuration for, and then actual in-use
subset of, websocket protocol extensions for a connection. Currently
only permessage-deflate is supported, but having an enum is zero-cost
when it has only zero or one variants, and an empty struct takes up no
space.

This also lets us reduce the amount of code that needs to be annotated
with `#[cfg(feature = "deflate")]` since calling code can always assume
that the PerMessageCompressionContext type exists even if its method
impls are sometimes no-ops.

Based on work by Benjamin Swart <[email protected]>
Make the necessary changes to the websocket protocol implementation to
use the PMCE compressor and decompressor when the connection has one
enabled.

This doesn't wire up the negotiation during handshaking, just
enables usage for an already-established connection.

Based on work by Benjamin Swart <[email protected]>
Also enable construction of WebSocket instances with configured
extensions.

Based on work by Benjamin Swart <[email protected]>
Switch to using flate2's Compress and Decompress types directly instead of via 
std::io::Write-implementing wrappers. This lets us avoid an intermediate buffer 
in each direction.
Add an argument to control how much compressed data is returned before an error 
is returned. Pass down the remaining per-message limit when decompressing a 
frame.
@akonradi-signal
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants