Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.

Commit 5237c85

Browse files
committed
http: compress: Add a couple of helper functions
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 <a.clayton@nginx.com>
1 parent 3010704 commit 5237c85

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/nxt_http_compression.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,36 @@ static void print_comp_config(size_t n)
151151
}
152152
}
153153

154+
155+
static ssize_t
156+
nxt_http_comp_compress(uint8_t *dst, size_t dst_size, const uint8_t *src,
157+
size_t src_size, bool last)
158+
{
159+
nxt_http_comp_ctx_t *ctx = &compressor_ctx;
160+
nxt_http_comp_compressor_t *compressor;
161+
const nxt_http_comp_operations_t *cops;
162+
163+
compressor = &enabled_compressors[ctx->idx];
164+
cops = compressor->type->cops;
165+
166+
return cops->deflate(&ctx->ctx, src, src_size, dst, dst_size, last);
167+
}
168+
169+
170+
static size_t
171+
nxt_http_comp_bound(size_t size)
172+
{
173+
nxt_http_comp_ctx_t *ctx = &compressor_ctx;
174+
nxt_http_comp_compressor_t *compressor;
175+
const nxt_http_comp_operations_t *cops;
176+
177+
compressor = &enabled_compressors[ctx->idx];
178+
cops = compressor->type->cops;
179+
180+
return cops->bound(&ctx->ctx, size);
181+
}
182+
183+
154184
bool
155185
nxt_http_comp_wants_compression(void)
156186
{

0 commit comments

Comments
 (0)