summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_router.c
diff options
context:
space:
mode:
authorAndrew Clayton <a.clayton@nginx.com>2024-11-20 17:02:22 +0000
committerAndrew Clayton <a.clayton@nginx.com>2024-11-29 00:45:24 +0000
commit4ddf19c3fccc4265c46139addabe354c99b1587b (patch)
tree6b901ace62a90886a0e376fea326700e54bc1d10 /src/nxt_router.c
parent7a043c0a5e110fb6b8e9e22c958d8bb483101067 (diff)
downloadunit-4ddf19c3fccc4265c46139addabe354c99b1587b.tar.gz
unit-4ddf19c3fccc4265c46139addabe354c99b1587b.tar.bz2
http: Wire up HTTP compression support to the config system
This exposes a new "settings.http.compression" configuration object. Under which are types & compressors objects. types is used to specify what MIME types should be considered compressible. compressors is used to configure an array of compressors that are available. For each of these, you specify the encoding, e.g gzip and optional level and min_length parameters. Where level is what compression level to use and min_length is the minimum length of data that should be compressed. By default the default compression level for the specified compressor is used and there is no minimum data length considered for compression. It may look something like "settings": { "http": { "server_version": true, "static": { "mime_types": { "text/x-c": [ ".c", ".h" ] } }, "compression": { "types": [ "text/*" ], "compressors": [ { "encoding": "gzip", "level": 3, "min_length": 2048 }, { "encoding": "deflate", "min_length": 1024 }, { "encoding": "zstd", "min_length": 2048 }, { "encoding": "br", "min_length": 256 } ] } } }, Currently this is a global option that will effect both static and application responses. In future it should be possible to add per-application (and perhaps even per-static) configuration. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
Diffstat (limited to 'src/nxt_router.c')
-rw-r--r--src/nxt_router.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/nxt_router.c b/src/nxt_router.c
index 44ea823b..d2486c9f 100644
--- a/src/nxt_router.c
+++ b/src/nxt_router.c
@@ -21,6 +21,7 @@
#include <nxt_router_request.h>
#include <nxt_app_queue.h>
#include <nxt_port_queue.h>
+#include <nxt_http_compression.h>
#define NXT_SHARED_PORT_ID 0xFFFFu
@@ -1680,6 +1681,8 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
static const nxt_str_t static_path = nxt_string("/settings/http/static");
static const nxt_str_t websocket_path =
nxt_string("/settings/http/websocket");
+ static const nxt_str_t compression_path =
+ nxt_string("/settings/http/compression");
static const nxt_str_t forwarded_path = nxt_string("/forwarded");
static const nxt_str_t client_ip_path = nxt_string("/client_ip");
#if (NXT_HAVE_OTEL)
@@ -2044,6 +2047,8 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
nxt_str_null(&skcf->body_temp_path);
if (http != NULL) {
+ nxt_conf_value_t *comp;
+
ret = nxt_conf_map_object(mp, http, nxt_router_http_conf,
nxt_nitems(nxt_router_http_conf),
skcf);
@@ -2051,6 +2056,11 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
nxt_alert(task, "http map error");
goto fail;
}
+
+ comp = nxt_conf_get_path(root, &compression_path);
+ if (comp != NULL) {
+ nxt_http_comp_compression_init(task, rtcf, comp);
+ }
}
if (websocket != NULL) {