Allow applications to independently own outgoing PMD compression and incoming PMD decompression while retaining Beast’s WebSocket negotiation, framing, and I/O.

Aperta
#3,117 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
networking

Direzione di ricerca

Start with websocket::permessage_deflate, websocket::stream, and permessage_deflate_status, then review the existing read, write, async, and partial-write operations alongside RFC 7692. Done means applications can own outgoing compression and incoming decompression while Beast retains negotiation, framing, I/O, control-frame handling, and validation, with the specified status and message-state queries.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

In my application I want to close ws connection on uncontrolled queue growth (due to networking issues). What happens now when permesagedeflate(PMD) is enabled the queue grows due to bottleneck introduced by deflation. Right now there is no clean way to distinguish network from compressor contention. I want to be able to account for compression cost on message generation side so that I can throttle the source instead of dropping the connection. This proposal also solves #3014 and #1756.

I propose we add two independent fields to websocket::permessage_deflate:

bool external_compression = false;   // Outgoing messages
bool external_decompression = false; // Incoming messages

With external compression enabled, reuse existing write, async_write, and partial-write operations:

  • compress(true) declares that the supplied bytes are already a valid PMD-encoded payload. Beast skips compression and sets RSV1 on the first frame.
  • compress(false) declares an ordinary, uncompressed payload.
  • The setting is captured at message start and applies to all its fragments.
  • compLevel, memLevel, and msg_size_threshold do not affect outgoing payloads in this mode.
  • A compressed write without negotiated PMD fails before transmission.

Then conceptually:

ws.compress(message.is_compressed);
ws.async_write(net::buffer(message.payload), handler);

Beast continues handling fragmentation, masking, and text/binary opcodes. The opcode describes the original, decoded message.

With external decompression enabled, reuse existing read operations and add:

bool websocket::stream::got_compressed() const;

This query reports the received message’s RSV1 state after a successful read operation. Its value remains fixed throughout the message. In normal mode, Beast still returns decoded data; in external mode, compressed payloads remain encoded.

Operation Behavior in external decompression mode
read / async_read Append unmasked payload bytes until the current WebSocket message is complete, joining its fragments.
read_some / async_read_some Deliver chunks of unmasked payload bytes without waiting for the complete message.

Neither operation inflates data nor inserts synthetic PMD trailer bytes. Read chunks need not align with DEFLATE blocks.

is_message_done() identifies completion of the WebSocket message, based on consuming its final fragment. A partial read may complete the message with zero additional payload bytes when the final fragment is empty. got_text() and got_binary() retain their existing meaning.

Beast continues processing control frames and validating WebSocket framing, including rejecting RSV1 when PMD was not negotiated.

Extend permessage_deflate_status with:

bool client_no_context_takeover = false;
bool server_no_context_takeover = false;

These report negotiated results when PMD is active:

  • client_no_context_takeover governs client-to-server traffic.
  • server_no_context_takeover governs server-to-client traffic.

Together with the existing negotiated window sizes, they provide the settings needed by external codecs.

For each external direction, the application owns RFC 7692 payload processing, including message finalization and compression history. Incoming PMD finalization occurs once at WebSocket message completion, not after every read chunk. The external decoder must handle valid DEFLATE block arrangements and reject malformed or truncated payloads.

For externally decoded compressed messages, the application also validates decoded UTF-8 and enforces decoded-size limits during inflation. In external decompression mode, read_message_max bounds the received encoded payload across the whole message; it cannot bound its decoded size.

Transfer counts measure bytes supplied to or returned by Beast—encoded payload bytes where applicable, excluding WebSocket framing. Existing buffer-lifetime, serialization, and cancellation rules remain applicable.

PMD handshake validation, including window and context-takeover negotiation, remains Beast’s responsibility. These options change codec ownership without changing negotiation rules.

I can prepare POC PR for this if you believe it to be the right direction.

Lingua principale
C++
Stelle
4.8k
Fork
697
Merge medio
20h 38m
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di boostorg/beast

Tutte le issue di boostorg/beast

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.