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

Compression middleware and built-in zlib/brotli/zstd backends. More...

#include <cwist/sys/app/compress.h>
#include <cwist/core/mem/alloc.h>
#include <cwist/net/http/http.h>
#include <zlib.h>
#include <brotli/encode.h>
#include <zstd.h>
#include <string.h>
#include <strings.h>
#include <stdio.h>
#include <stdlib.h>
#include "../../net/http/async_internal.h"
Include dependency graph for compress.c:

Go to the source code of this file.

Macros

#define _POSIX_C_SOURCE   200809L
 
#define CWIST_MAX_BACKENDS   8
 

Functions

void cwist_compress_register_backend (const cwist_compress_backend *backend)
 Register a compression backend for use by the middleware.
 
void cwist_compress_unregister_all (void)
 Remove all registered compression backends.
 
const cwist_compress_backend * cwist_compress_backend_gzip (void)
 Get the built-in gzip backend.
 
const cwist_compress_backend * cwist_compress_backend_deflate (void)
 Get the built-in deflate backend.
 
const cwist_compress_backend * cwist_compress_backend_brotli (void)
 Get the built-in Brotli backend.
 
const cwist_compress_backend * cwist_compress_backend_zstd (void)
 Get the built-in zstd backend.
 
cwist_middleware_func cwist_mw_compress (size_t min_body_size)
 Create the response compression middleware.
 

Detailed Description

Compression middleware and built-in zlib/brotli/zstd backends.

Definition in file compress.c.

Macro Definition Documentation

◆ _POSIX_C_SOURCE

#define _POSIX_C_SOURCE   200809L

Definition at line 6 of file compress.c.

◆ CWIST_MAX_BACKENDS

#define CWIST_MAX_BACKENDS   8

Definition at line 19 of file compress.c.

Function Documentation

◆ cwist_compress_backend_brotli()

const cwist_compress_backend * cwist_compress_backend_brotli ( void  )

Get 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  )

Get the built-in 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  )

Get the built-in 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  )

Get the built-in 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 for use by the middleware.

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  )

Remove all registered 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)

Create the response compression middleware.

Response compression middleware factory.

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.