KEEL 1.0.0
Minimal C11 HTTP client/server library built on epoll/kqueue/io_uring/poll
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
compress.h File Reference
#include <keel/allocator.h>
#include <keel/response.h>
#include <stddef.h>
Include dependency graph for compress.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  KlCompress
 
struct  KlCompressConfig
 Compression configuration for KlConfig. More...
 
struct  KlCompressStream
 Compressed streaming handle. More...
 

Typedefs

typedef struct KlCompress KlCompress
 Pluggable compression vtable.
 
typedef struct KlCompressCtx KlCompressCtx
 Opaque per-server compression context (algorithm config, level). User-owned — KEEL never inspects or modifies this.
 
typedef KlCompress *(* KlCompressFactory) (KlCompressCtx *ctx, KlAllocator *alloc)
 Factory creates a KlCompress session from the shared context.
 
typedef struct KlCompressConfig KlCompressConfig
 Compression configuration for KlConfig.
 

Functions

int kl_response_body_compress (KlResponse *res, KlCompressConfig *cfg, const char *data, size_t len)
 Compress a buffer body and set it on the response.
 
int kl_compress_stream_begin (KlResponse *res, KlCompressConfig *cfg, int status, KlCompressStream *cs)
 Begin a compressed chunked streaming response.
 
int kl_compress_stream_write (KlCompressStream *cs, const char *data, size_t len)
 Write data to a compressed stream.
 
int kl_compress_stream_end (KlCompressStream *cs)
 End a compressed stream.
 

Typedef Documentation

◆ KlCompress

typedef struct KlCompress 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

typedef struct KlCompressCtx KlCompressCtx

Opaque per-server compression context (algorithm config, level). User-owned — KEEL never inspects or modifies this.

◆ KlCompressFactory

typedef KlCompress *(* KlCompressFactory) (KlCompressCtx *ctx, KlAllocator *alloc)

Factory creates a KlCompress session from the shared context.

Parameters
ctxShared compression context (algorithm, level).
allocAllocator for session resources.
Returns
New compression session, or NULL on failure.

◆ KlCompressConfig

Compression configuration for KlConfig.

Function Documentation

◆ kl_response_body_compress()

int kl_response_body_compress ( KlResponse res,
KlCompressConfig cfg,
const char *  data,
size_t  len 
)

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
resResponse to set body on.
cfgCompression config (factory + context).
dataBody data to compress.
lenBody data length.
Returns
0 on success, -1 on error.

◆ kl_compress_stream_begin()

int kl_compress_stream_begin ( KlResponse res,
KlCompressConfig cfg,
int  status,
KlCompressStream cs 
)

Begin a compressed chunked streaming response.

Sets Content-Encoding and Vary headers, starts chunked stream, and initializes the compress stream handle.

Parameters
resResponse.
cfgCompression config.
statusHTTP status code.
csCompress 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
csCompress stream handle.
dataData to compress and write.
lenData length.
Returns
0 on success, -1 on error.

◆ kl_compress_stream_end()

int kl_compress_stream_end ( KlCompressStream cs)

End a compressed stream.

Flushes remaining compressed data (trailer), destroys the compression session, and ends the underlying chunked stream.

Parameters
csCompress stream handle.
Returns
0 on success, -1 on error.