diff options
| author | Alejandro Colomar <alx@nginx.com> | 2023-08-24 14:09:18 +0200 |
|---|---|---|
| committer | Alejandro Colomar <alx@kernel.org> | 2023-10-25 13:38:42 +0200 |
| commit | d5906fc0a30d51bbd25f0b7026fba977962e6042 (patch) | |
| tree | 9e8227c66645f416833cd6e0269b3f32f1379322 /src/nxt_http_compress.c | |
| parent | e357f665abad29dfdf94103d0ad82774d2ec3d14 (diff) | |
| download | unit-d5906fc0a30d51bbd25f0b7026fba977962e6042.tar.gz unit-d5906fc0a30d51bbd25f0b7026fba977962e6042.tar.bz2 | |
HTTP: compress: added configurable threshold for Content-Length.
With this, short responses, that is, responses with a body of up to
content_length_threshold bytes, won't be compressed. The default value
is 20, as in NGINX.
Signed-off-by: Alejandro Colomar <alx@nginx.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Diffstat (limited to 'src/nxt_http_compress.c')
| -rw-r--r-- | src/nxt_http_compress.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/nxt_http_compress.c b/src/nxt_http_compress.c index 55e20e3a..763d1266 100644 --- a/src/nxt_http_compress.c +++ b/src/nxt_http_compress.c @@ -37,6 +37,11 @@ static nxt_conf_map_t nxt_http_compress_conf[] = { NXT_CONF_MAP_INT8, offsetof(nxt_http_compress_conf_t, level), }, + { + nxt_string("min_length"), + NXT_CONF_MAP_SIZE, + offsetof(nxt_http_compress_conf_t, min_len), + }, }; @@ -56,6 +61,7 @@ nxt_http_compress_init(nxt_router_conf_t *rtcf, nxt_http_action_t *action, } conf->level = NXT_DEFAULT_COMPRESSION; + conf->min_len = 20; ret = nxt_conf_map_object(mp, acf->compress, nxt_http_compress_conf, nxt_nitems(nxt_http_compress_conf), conf); @@ -98,3 +104,30 @@ nxt_http_compress_append_field(nxt_task_t *task, nxt_http_request_t *r, return NXT_OK; } + + +ssize_t +nxt_http_compress_resp_content_length(nxt_http_response_t *resp) +{ + size_t cl; + nxt_int_t err; + nxt_str_t str; + + if (resp->content_length_n != -1) { + return resp->content_length_n; + } + + if (resp->content_length == NULL) { + return -1; + } + + str.length = resp->content_length->value_length; + str.start = resp->content_length->value; + + cl = nxt_ustrtoul(&str, &err); + if (err == NXT_ERROR) { + return -1; + } + + return cl; +} |
