Skip to content

Add optional WebSocket permessage-deflate (RFC 7692) support #761

Description

@sjquant

Is your feature request related to a problem? Please describe.

Our Socket.IO clients are browser-based and offer the permessage-deflate WebSocket extension during the upgrade handshake.

However, the WebSocket transport currently does not negotiate this extension, so Socket.IO event payloads are sent uncompressed. For payload-heavy or high-frequency events, this significantly increases outbound bandwidth and egress costs.

We would like to keep using Socket.IO features such as namespaces, rooms, acks, and Engine.IO fallback, while enabling compression for the WebSocket transport.

Describe the solution you'd like

Add optional RFC 7692 permessage-deflate support to the Engine.IO WebSocket transport.

Ideally, this would:

  • Negotiate Sec-WebSocket-Extensions: permessage-deflate during the WebSocket
    upgrade when the client offers it.
  • Transparently decompress incoming compressed messages and compress outgoing
    WebSocket messages.
  • Preserve existing Socket.IO and Engine.IO packet behavior.
  • Be disabled by default, or exposed through an explicit SocketIoConfig /
    EngineIoConfig option.
  • Allow resource-related settings such as:
    • compression threshold;
    • compression level;
    • server_no_context_takeover and client_no_context_takeover;
    • maximum window bits.

A configuration API could look roughly like:

let config = SocketIoConfig::default()
    .permessage_deflate(
        PerMessageDeflateConfig::default()
            .enabled(true)
            .threshold(1024)
            .server_no_context_takeover(true)
            .client_no_context_takeover(true),
    );

The exact API and defaults are, of course, up to the maintainers.

Describe alternatives you've considered

  • Running a separate WebSocket-aware compression gateway in front of socketioxide. This can terminate PMD toward clients and proxy uncompressed WebSocket frames to the Rust backend, but adds another service and connection hop.
  • Application-level compression of binary payloads. This requires client changes and does not provide transparent compression for normal Socket.IO events.

Additional context

permessage-deflate is defined by RFC 7692: https://www.rfc-editor.org/rfc/rfc7692

This would be particularly valuable for deployments with browser clients and large or repetitive server-to-client Socket.IO payloads. It should remain optional because compression trades network usage for CPU and per-connection memory.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions