diff options
author | Alejandro Colomar <alx@nginx.com> | 2023-08-23 17:23:49 +0200 |
---|---|---|
committer | Alejandro Colomar <alx@nginx.com> | 2023-09-04 03:40:32 +0200 |
commit | 7ecdc3d190e449f04ac69d62f437399851035028 (patch) | |
tree | 8294f5d8c857ddd5b442240d365799b8b3730bba | |
parent | 00801288b07d9d7c9557667b8020bab61375ca1c (diff) | |
download | unit-7ecdc3d190e449f04ac69d62f437399851035028.tar.gz unit-7ecdc3d190e449f04ac69d62f437399851035028.tar.bz2 |
HTTP: compress: added configurable "level" of compression.
-rw-r--r-- | src/nxt_conf_validation.c | 3 | ||||
-rw-r--r-- | src/nxt_http_compress.c | 10 | ||||
-rw-r--r-- | src/nxt_http_compress.h | 4 | ||||
-rw-r--r-- | 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 <stdint.h> + #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 <stddef.h> +#include <stdint.h> #include <zlib.h> @@ -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; } |