### Motivation:
zlib stores the address of `z_stream` in its internal state and expects
that
address to remain stable across calls. Storing `z_stream` inline in
movable
Swift value types does not provide that guarantee and can cause
`Z_STREAM_ERROR` during cleanup.
Fixes#308.
### Modifications:
- Make the internal compressor and decompressor reference owners of
separately
allocated `z_stream` storage.
- Pass the stable pointer to every zlib initialization, processing, and
cleanup
call.
- Keep lifecycle state with the pointer owner and make conditional
cleanup
idempotent.
- Add regression tests covering failed initialization recovery, multiple
compression and decompression calls, repeated lifecycles, and
deallocation
cleanup.
### Result:
zlib observes the same `z_stream` address for each complete lifecycle,
while
stream cleanup remains single-owner and safe against repeated shutdown.
### Motivation:
`NIOHTTPRequestDecompressor` / `NIOHTTPResponseDecompressor` keep their
state in a
stored `var decompressor` (a `struct`) and forwarded downstream
(`fireChannelRead` /
`fireErrorCaught`) from inside that struct's `mutating` `channelRead`,
i.e. while an
exclusive (modify) access to the stored property was still open. If
firing downstream
synchronously re-enters the handler's `channelRead`, a second exclusive
access is
opened and the program traps with `Fatal access conflict detected`
(SIGABRT).
This reproduces in production with AsyncHTTPClient over HTTP/2 and
`decompression = .enabled`: a compressed response is mid-decompress when
a
decompression error closes the stream, and the buffered read
re-delivered on the
stream-close path re-enters `channelRead` on the same decompressor.
### Modifications:
- The body decompression is now expressed as a
`NIOSingleStepByteToMessageDecoder`,
driven by a `NIOSingleStepByteToMessageProcessor`. The handler pulls one
decompressed
buffer at a time and forwards it only after `decode` has returned, so
the decoder
relinquishes its exclusive access before anything is fired downstream.
- The shared driver is now a `class`, so the head/end forwarding paths
are re-entrancy
safe for the same reason.
- The zlib stream is torn down in the decoder's `deinit`, which
additionally fixes a
leak when a message ends without a final `.end`.
- No public API changes.
### Result:
Synchronous re-entry of `channelRead` no longer traps. Adds regression
tests covering
the forward and error re-entry paths on both decompressors; all existing
decompression
tests (limits, trailing data, truncation, multi-message reuse) continue
to pass.
Fixes#314
---------
Co-authored-by: George Barnett <gbarnett@apple.com>
### Motivation
We want to maintain less code.
### Changes
- Unifi the request and response decompression by extracting the decompression code into a `Decompressor` struct
- `NIOHTTPRequestDecompressor` calls out to `Decompressor` internally
- `NIOHTTPResponseDecompressor` calls out to `Decompressor` internally
### Result
- Less code to maintain
- Less subtle bugs