Skip to content

Commit 523d422

Browse files
committed
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 <[email protected]>
1 parent 85a0091 commit 523d422

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/nxt_http_compression.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,35 @@ static const nxt_http_comp_type_t nxt_http_comp_compressors[] = {
137137
};
138138

139139

140+
static ssize_t
141+
nxt_http_comp_compress(uint8_t *dst, size_t dst_size, const uint8_t *src,
142+
size_t src_size, bool last)
143+
{
144+
nxt_http_comp_ctx_t *ctx = nxt_http_comp_ctx();
145+
nxt_http_comp_compressor_t *compressor;
146+
const nxt_http_comp_operations_t *cops;
147+
148+
compressor = &nxt_http_comp_enabled_compressors[ctx->idx];
149+
cops = compressor->type->cops;
150+
151+
return cops->deflate(&ctx->ctx, src, src_size, dst, dst_size, last);
152+
}
153+
154+
155+
static size_t
156+
nxt_http_comp_bound(size_t size)
157+
{
158+
nxt_http_comp_ctx_t *ctx = nxt_http_comp_ctx();
159+
nxt_http_comp_compressor_t *compressor;
160+
const nxt_http_comp_operations_t *cops;
161+
162+
compressor = &nxt_http_comp_enabled_compressors[ctx->idx];
163+
cops = compressor->type->cops;
164+
165+
return cops->bound(&ctx->ctx, size);
166+
}
167+
168+
140169
bool
141170
nxt_http_comp_wants_compression(void)
142171
{

0 commit comments

Comments
 (0)