From 0569065aa583470b8dd2689f2aae53f57b74fe46 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Wed, 23 Aug 2023 17:23:49 +0200 Subject: HTTP: compress: added configurable "level" of compression. Signed-off-by: Alejandro Colomar Signed-off-by: Alejandro Colomar --- src/nxt_conf_validation.c | 3 +++ src/nxt_http_compress.c | 10 ++++++++++ src/nxt_http_compress.h | 4 ++++ src/nxt_http_compress_gzip.c | 8 ++++++-- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c index 0e1f7340..4943c603 100644 --- a/src/nxt_conf_validation.c +++ b/src/nxt_conf_validation.c @@ -1158,6 +1158,9 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_compress_members[] = { { .name = nxt_string("encoding"), .type = NXT_CONF_VLDT_STRING, + }, { + .name = nxt_string("level"), + .type = NXT_CONF_VLDT_INTEGER, }, NXT_CONF_VLDT_END diff --git a/src/nxt_http_compress.c b/src/nxt_http_compress.c index e27dd278..f78a16ed 100644 --- a/src/nxt_http_compress.c +++ b/src/nxt_http_compress.c @@ -23,12 +23,20 @@ #include "nxt_types.h" +#define NXT_DEFAULT_COMPRESSION (-1) + + static nxt_conf_map_t nxt_http_compress_conf[] = { { nxt_string("encoding"), NXT_CONF_MAP_STR, offsetof(nxt_http_compress_conf_t, encoding), }, + { + nxt_string("level"), + NXT_CONF_MAP_INT8, + offsetof(nxt_http_compress_conf_t, level), + }, }; @@ -47,6 +55,8 @@ nxt_http_compress_init(nxt_router_conf_t *rtcf, nxt_http_action_t *action, return NXT_ERROR; } + conf->level = NXT_DEFAULT_COMPRESSION; + ret = nxt_conf_map_object(mp, acf->compress, nxt_http_compress_conf, nxt_nitems(nxt_http_compress_conf), conf); if (nxt_slow_path(ret == NXT_ERROR)) { diff --git a/src/nxt_http_compress.h b/src/nxt_http_compress.h index 57bebd1c..19075025 100644 --- a/src/nxt_http_compress.h +++ b/src/nxt_http_compress.h @@ -9,6 +9,8 @@ #include "nxt_router.h" +#include + #include "nxt_http.h" #include "nxt_main.h" #include "nxt_router.h" @@ -22,6 +24,8 @@ struct nxt_http_compress_conf_s { nxt_int_t (*handler)(nxt_task_t *task, nxt_http_request_t *r, nxt_http_compress_conf_t *conf); + + int8_t level; }; diff --git a/src/nxt_http_compress_gzip.c b/src/nxt_http_compress_gzip.c index 75ed9155..169b463d 100644 --- a/src/nxt_http_compress_gzip.c +++ b/src/nxt_http_compress_gzip.c @@ -7,6 +7,7 @@ #include "nxt_http_compress_gzip.h" #include +#include #include @@ -32,6 +33,8 @@ struct nxt_http_compress_gzip_ctx_s { nxt_http_request_t *r; nxt_buf_t *b; + int8_t level; + z_stream z; }; @@ -97,14 +100,15 @@ nxt_http_compress_gzip_ctx(nxt_task_t *task, nxt_http_request_t *r, return NULL; } + ctx->level = conf->level; ctx->r = r; z = &ctx->z; z->zalloc = NULL; z->zfree = NULL; z->opaque = NULL; - ret = deflateInit2(z, Z_DEFAULT_COMPRESSION, Z_DEFLATED, MAX_WBITS + 16, - MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY); + ret = deflateInit2(z, ctx->level, Z_DEFLATED, MAX_WBITS + 16, MAX_MEM_LEVEL, + Z_DEFAULT_STRATEGY); if (nxt_slow_path(ret != 0)) { return NULL; } -- cgit