#include <keel/allocator.h>
#include <keel/response.h>
#include <stddef.h>
Go to the source code of this file.
◆ KlCompress
Pluggable compression vtable.
Users implement this interface to provide compression (gzip, deflate, zstd). One KlCompress instance is created per compress operation via the factory — not pre-allocated per connection (deflate state is ~300KB).
◆ KlCompressCtx
Opaque per-server compression context (algorithm config, level). User-owned — KEEL never inspects or modifies this.
◆ KlCompressFactory
Factory creates a KlCompress session from the shared context.
- Parameters
-
| ctx | Shared compression context (algorithm, level). |
| alloc | Allocator for session resources. |
- Returns
- New compression session, or NULL on failure.
◆ KlCompressConfig
Compression configuration for KlConfig.
◆ kl_response_body_compress()
Compress a buffer body and set it on the response.
Creates a compression session, compresses data, sets Content-Encoding and Vary: Accept-Encoding headers. If compression expands the data, falls back to uncompressed (no Content-Encoding header).
- Parameters
-
| res | Response to set body on. |
| cfg | Compression config (factory + context). |
| data | Body data to compress. |
| len | Body data length. |
- Returns
- 0 on success, -1 on error.
◆ kl_compress_stream_begin()
Begin a compressed chunked streaming response.
Sets Content-Encoding and Vary headers, starts chunked stream, and initializes the compress stream handle.
- Parameters
-
| res | Response. |
| cfg | Compression config. |
| status | HTTP status code. |
| cs | Compress stream handle to initialize (caller-owned). |
- Returns
- 0 on success, -1 on error.
◆ kl_compress_stream_write()
| int kl_compress_stream_write |
( |
KlCompressStream * |
cs, |
|
|
const char * |
data, |
|
|
size_t |
len |
|
) |
| |
Write data to a compressed stream.
Feeds data through the compressor and emits compressed chunks to the underlying chunked stream.
- Parameters
-
| cs | Compress stream handle. |
| data | Data to compress and write. |
| len | Data length. |
- Returns
- 0 on success, -1 on error.
◆ kl_compress_stream_end()
End a compressed stream.
Flushes remaining compressed data (trailer), destroys the compression session, and ends the underlying chunked stream.
- Parameters
-
| cs | Compress stream handle. |
- Returns
- 0 on success, -1 on error.