diff options
author | Andrew Clayton <a.clayton@nginx.com> | 2024-06-11 00:24:28 +0100 |
---|---|---|
committer | Andrew Clayton <a.clayton@nginx.com> | 2024-06-19 16:15:04 +0100 |
commit | 4071de5797da0a104b4983fc1ad393d3744b6128 (patch) | |
tree | 003803a861f2609cfae58db412e1c3d7ee6dc8f9 /src/nxt_http_compression.h | |
parent | ea5c41b8056997ed40138020272b5159271f1b87 (diff) | |
download | unit-compr.tar.gz unit-compr.tar.bz2 |
[WIP] HTTP Compression Supportcompr
Diffstat (limited to 'src/nxt_http_compression.h')
-rw-r--r-- | src/nxt_http_compression.h | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/nxt_http_compression.h b/src/nxt_http_compression.h new file mode 100644 index 00000000..a76f3993 --- /dev/null +++ b/src/nxt_http_compression.h @@ -0,0 +1,91 @@ +/* + * Copyright (C) Andrew Clayton + * Copyright (C) F5, Inc. + */ + +#ifndef _NXT_COMPRESSION_H_INCLUDED_ +#define _NXT_COMPRESSION_H_INCLUDED_ + +#include <nxt_auto_config.h> + +#include <stddef.h> +#include <stdint.h> +#include <stdbool.h> + +#if NXT_HAVE_ZLIB +#include <zlib.h> +#endif + +#if NXT_HAVE_ZSTD +#include <zstd.h> +#endif + +#if NXT_HAVE_BROTLI +#include <brotli/encode.h> +#endif + +#include <nxt_main.h> +#include <nxt_router.h> +#include <nxt_string.h> +#include <nxt_conf.h> + +#if NXT_HAVE_ZLIB +#define NXT_HTTP_COMP_ZLIB_DEFAULT_LEVEL Z_DEFAULT_COMPRESSION +#endif +#if NXT_HAVE_ZSTD +#define NXT_HTTP_COMP_ZSTD_DEFAULT_LEVEL ZSTD_CLEVEL_DEFAULT +#endif +#if NXT_HAVE_BROTLI +#define NXT_HTTP_COMP_BROTLI_DEFAULT_LEVEL BROTLI_DEFAULT_QUALITY +#endif + +typedef struct nxt_http_comp_compressor_ctx_s nxt_http_comp_compressor_ctx_t; +typedef struct nxt_http_comp_operations_s nxt_http_comp_operations_t; + +struct nxt_http_comp_compressor_ctx_s { + int8_t level; + + union { +#if NXT_HAVE_ZLIB + z_stream zlib_ctx; +#endif +#if NXT_HAVE_ZSTD + ZSTD_CStream *zstd_ctx; +#endif +#if NXT_HAVE_BROTLI + BrotliEncoderState *brotli_ctx; +#endif + }; +}; + +struct nxt_http_comp_operations_s { + void (*init)(nxt_http_comp_compressor_ctx_t *ctx); + size_t (*compressed_size)(const nxt_http_comp_compressor_ctx_t *ctx, + size_t in_len); + ssize_t (*deflate)(nxt_http_comp_compressor_ctx_t *ctx, + const uint8_t *in_buf, size_t in_len, + uint8_t *out_buf, size_t out_len, bool last); + void (*free_ctx)(const nxt_http_comp_compressor_ctx_t *ctx); +}; + +#if NXT_HAVE_ZLIB +extern const nxt_http_comp_operations_t nxt_comp_deflate_ops; +extern const nxt_http_comp_operations_t nxt_comp_gzip_ops; +#endif + +#if NXT_HAVE_ZSTD +extern const nxt_http_comp_operations_t nxt_comp_zstd_ops; +#endif + +#if NXT_HAVE_BROTLI +extern const nxt_http_comp_operations_t nxt_comp_brotli_ops; +#endif + +extern bool nxt_http_comp_compressor_is_valid(const nxt_str_t *token); +extern nxt_int_t nxt_http_comp_check_compression(nxt_task_t *task, + nxt_http_request_t *r); +extern nxt_int_t nxt_http_comp_compress_response(nxt_buf_t *out); +extern nxt_int_t nxt_http_comp_compression_init(nxt_task_t *task, + nxt_router_conf_t *rtcf, const nxt_conf_value_t *comp_conf); + +#endif /* _NXT_COMPRESSION_H_INCLUDED_ */ |