Skip to content

Commit

Permalink
http: compress: Add a couple of helper functions
Browse files Browse the repository at this point in the history
This adds two helper function 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 <[email protected]>
  • Loading branch information
ac000 committed Nov 29, 2024
1 parent 3010704 commit 5237c85
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/nxt_http_compression.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,36 @@ static void print_comp_config(size_t n)
}
}


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 = &compressor_ctx;
nxt_http_comp_compressor_t *compressor;
const nxt_http_comp_operations_t *cops;

compressor = &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 = &compressor_ctx;
nxt_http_comp_compressor_t *compressor;
const nxt_http_comp_operations_t *cops;

compressor = &enabled_compressors[ctx->idx];
cops = compressor->type->cops;

return cops->bound(&ctx->ctx, size);
}


bool
nxt_http_comp_wants_compression(void)
{
Expand Down

0 comments on commit 5237c85

Please sign in to comment.