diff options
| author | Andrew Clayton <a.clayton@nginx.com> | 2024-11-29 15:43:11 +0000 |
|---|---|---|
| committer | Andrew Clayton <a.clayton@nginx.com> | 2025-04-14 18:11:53 +0100 |
| commit | 523d42269ff89490b9dad25565121ea5e7696881 (patch) | |
| tree | 3a0d6af9cdd6c89434ea67cadcf5b46479e16960 | |
| parent | 85a00914df5d603649b5177a2bca07f0314d6488 (diff) | |
| download | unit-523d42269ff89490b9dad25565121ea5e7696881.tar.gz unit-523d42269ff89490b9dad25565121ea5e7696881.tar.bz2 | |
http: compress: Add a couple of helper functions
This adds two helper functions that will be used in subsequent commits.
nxt_http_comp_compress() does the actual compression.
nxt_http_comp_bound() returns the maximum compressed size for the given
size.
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
| -rw-r--r-- | src/nxt_http_compression.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/nxt_http_compression.c b/src/nxt_http_compression.c index e6083ec3..6bd13fc9 100644 --- a/src/nxt_http_compression.c +++ b/src/nxt_http_compression.c @@ -137,6 +137,35 @@ static const nxt_http_comp_type_t nxt_http_comp_compressors[] = { }; +static ssize_t +nxt_http_comp_compress(uint8_t *dst, size_t dst_size, const uint8_t *src, + size_t src_size, bool last) +{ + nxt_http_comp_ctx_t *ctx = nxt_http_comp_ctx(); + nxt_http_comp_compressor_t *compressor; + const nxt_http_comp_operations_t *cops; + + compressor = &nxt_http_comp_enabled_compressors[ctx->idx]; + cops = compressor->type->cops; + + return cops->deflate(&ctx->ctx, src, src_size, dst, dst_size, last); +} + + +static size_t +nxt_http_comp_bound(size_t size) +{ + nxt_http_comp_ctx_t *ctx = nxt_http_comp_ctx(); + nxt_http_comp_compressor_t *compressor; + const nxt_http_comp_operations_t *cops; + + compressor = &nxt_http_comp_enabled_compressors[ctx->idx]; + cops = compressor->type->cops; + + return cops->bound(&ctx->ctx, size); +} + + bool nxt_http_comp_wants_compression(void) { |
