cwist
Modern C web framework with libttak runtime
Loading...
Searching...
No Matches
compress.h File Reference

Compression middleware with swappable backend interface. More...

#include <cwist/sys/app/app.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.

Classes

struct  cwist_compress_backend
 Compression backend vtable. More...
 

Typedefs

typedef struct cwist_compress_backend cwist_compress_backend
 Compression backend vtable.
 

Functions

void cwist_compress_register_backend (const cwist_compress_backend *backend)
 Register a compression backend.
 
void cwist_compress_unregister_all (void)
 Unregister all compression backends.
 
const cwist_compress_backend * cwist_compress_backend_gzip (void)
 Returns the built-in zlib/gzip backend.
 
const cwist_compress_backend * cwist_compress_backend_deflate (void)
 Returns the built-in zlib/deflate backend.
 
const cwist_compress_backend * cwist_compress_backend_brotli (void)
 Returns the built-in Brotli backend.
 
const cwist_compress_backend * cwist_compress_backend_zstd (void)
 Returns the built-in Zstandard (zstd) backend.
 
cwist_middleware_func cwist_mw_compress (size_t min_body_size)
 Compression middleware factory.
 

Detailed Description

Compression middleware with swappable backend interface.

Definition in file compress.h.

Typedef Documentation

◆ cwist_compress_backend

Compression backend vtable.

Implementations provide init/compress/finish/cleanup lifecycle hooks. The middleware uses this interface so backends can be swapped or extended (e.g., Brotli, zstd) without changing middleware logic.

Function Documentation

◆ cwist_compress_backend_brotli()

const cwist_compress_backend * cwist_compress_backend_brotli ( void  )

Returns the built-in Brotli backend.

Returns the built-in Brotli backend.

Returns
Pointer to the static Brotli backend descriptor.

Definition at line 350 of file compress.c.

◆ cwist_compress_backend_deflate()

const cwist_compress_backend * cwist_compress_backend_deflate ( void  )

Returns the built-in zlib/deflate backend.

Returns the built-in zlib/deflate backend.

Returns
Pointer to the static deflate backend descriptor.

Definition at line 173 of file compress.c.

◆ cwist_compress_backend_gzip()

const cwist_compress_backend * cwist_compress_backend_gzip ( void  )

Returns the built-in zlib/gzip backend.

Returns the built-in zlib/gzip backend.

Returns
Pointer to the static gzip backend descriptor.

Definition at line 165 of file compress.c.

◆ cwist_compress_backend_zstd()

const cwist_compress_backend * cwist_compress_backend_zstd ( void  )

Returns the built-in Zstandard (zstd) backend.

Returns the built-in Zstandard (zstd) backend.

Returns
Pointer to the static zstd backend descriptor.

Definition at line 524 of file compress.c.

◆ cwist_compress_register_backend()

void cwist_compress_register_backend ( const cwist_compress_backend *  backend)

Register a compression backend.

Parameters
backendPointer to a statically-allocated backend descriptor.

Register a compression backend.

Parameters
backendBackend to append to the registry. Ignored if NULL or if the registry is already full (CWIST_MAX_BACKENDS entries).

Definition at line 30 of file compress.c.

References CWIST_MAX_BACKENDS.

◆ cwist_compress_unregister_all()

void cwist_compress_unregister_all ( void  )

Unregister all compression backends.

Unregister all compression backends.

Definition at line 38 of file compress.c.

◆ cwist_mw_compress()

cwist_middleware_func cwist_mw_compress ( size_t  min_body_size)

Compression middleware factory.

Chooses a registered backend based on the request's Accept-Encoding header, runs the handler chain, then compresses the response body.

Parameters
min_body_sizeMinimum uncompressed body size (in bytes) to trigger compression. Use 0 to compress all bodies.
Returns
Middleware function pointer.

Compression middleware factory.

Parameters
min_body_sizeMinimum body size, in bytes, for compression to apply.
Returns
Middleware handler that compresses eligible responses.

Definition at line 713 of file compress.c.

References cap.