From 39db8691fe40adcfdb827c194636b87391c7c416 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Fri, 21 Jul 2023 13:58:37 +0200 Subject: Auto: zlib: added --no-zlib. Related to: HTTP: compress: gzip Signed-off-by: Alejandro Colomar --- auto/options | 4 ++++ auto/summary | 1 + auto/zlib | 39 +++++++++++++++++++++++++-------------- src/nxt_http_compress.c | 2 +- src/nxt_http_compress_gzip.c | 14 ++++++++++++-- src/nxt_http_compress_gzip.h | 9 +++++++++ 6 files changed, 52 insertions(+), 17 deletions(-) diff --git a/auto/options b/auto/options index 0550c699..ef0459f3 100644 --- a/auto/options +++ b/auto/options @@ -20,6 +20,8 @@ NXT_PCRE_LIB= NXT_REGEX=YES NXT_TRY_PCRE2=YES +NXT_ZLIB=YES + NXT_TLS=NO NXT_OPENSSL=NO NXT_GNUTLS=NO @@ -104,6 +106,8 @@ do --no-regex) NXT_REGEX=NO ;; --no-pcre2) NXT_TRY_PCRE2=NO ;; + --no-zlib) NXT_ZLIB=NO ;; + --openssl) NXT_OPENSSL=YES ;; --gnutls) NXT_GNUTLS=YES ;; --cyassl) NXT_CYASSL=YES ;; diff --git a/auto/summary b/auto/summary index 3aa41669..0e87b88a 100644 --- a/auto/summary +++ b/auto/summary @@ -29,6 +29,7 @@ Unit configuration summary: Unix domain sockets support: $NXT_UNIX_DOMAIN TLS support: ............... $NXT_OPENSSL Regex support: ............. $NXT_REGEX + zlib support: .............. $NXT_ZLIB NJS support: ............... $NXT_NJS process isolation: ......... $NXT_ISOLATION diff --git a/auto/zlib b/auto/zlib index dab30d38..b4e964c3 100644 --- a/auto/zlib +++ b/auto/zlib @@ -3,21 +3,32 @@ # Copyright (C) NGINX, Inc. -NXT_ZLIB_CFLAGS="$(pkgconf --cflags-only-I zlib 2>/dev/null || echo "")" -NXT_ZLIB_LIBS="$(pkgconf --libs zlib 2>/dev/null || echo "-lz")" +NXT_HAVE_ZLIB=no +NXT_ZLIB_CFLAGS= +NXT_ZLIB_LIBS= -nxt_feature="zlib" -nxt_feature_name=NXT_HAVE_ZLIB -nxt_feature_run=no -nxt_feature_incs=$NXT_ZLIB_CFLAGS -nxt_feature_libs=$NXT_ZLIB_LIBS -nxt_feature_test="#include +if [ $NXT_ZLIB = YES ]; then - #include + NXT_ZLIB_CFLAGS="$(pkgconf --cflags-only-I zlib 2>/dev/null || echo "")" + NXT_ZLIB_LIBS="$(pkgconf --libs zlib 2>/dev/null || echo "-lz")" - int main(void) { - puts(zlibVersion()); - return 0; - }" -. auto/feature + nxt_feature="zlib" + nxt_feature_name=NXT_HAVE_ZLIB + nxt_feature_run=no + nxt_feature_incs=$NXT_ZLIB_CFLAGS + nxt_feature_libs=$NXT_ZLIB_LIBS + nxt_feature_test="#include + + #include + + int main(void) { + puts(zlibVersion()); + return 0; + }" + . auto/feature + + if [ $nxt_found = yes ]; then + NXT_HAVE_ZLIB=YES + fi +fi diff --git a/src/nxt_http_compress.c b/src/nxt_http_compress.c index f78a16ed..55e20e3a 100644 --- a/src/nxt_http_compress.c +++ b/src/nxt_http_compress.c @@ -63,7 +63,7 @@ nxt_http_compress_init(nxt_router_conf_t *rtcf, nxt_http_action_t *action, return NXT_ERROR; } - if (nxt_str_eq(&conf->encoding, "gzip", strlen("gzip"))) { + if (NXT_WITH_ZLIB && nxt_str_eq(&conf->encoding, "gzip", strlen("gzip"))) { conf->handler = nxt_http_compress_gzip; } else { diff --git a/src/nxt_http_compress_gzip.c b/src/nxt_http_compress_gzip.c index 169b463d..db675ecf 100644 --- a/src/nxt_http_compress_gzip.c +++ b/src/nxt_http_compress_gzip.c @@ -9,8 +9,6 @@ #include #include -#include - #include #include "nxt_buf.h" @@ -25,6 +23,10 @@ #include "nxt_string.h" #include "nxt_types.h" +#if (NXT_WITH_ZLIB || __has_include()) +#include +#endif + typedef struct nxt_http_compress_gzip_ctx_s nxt_http_compress_gzip_ctx_t; @@ -35,7 +37,9 @@ struct nxt_http_compress_gzip_ctx_s { int8_t level; +#if (NXT_WITH_ZLIB) z_stream z; +#endif }; @@ -91,6 +95,9 @@ static nxt_http_compress_gzip_ctx_t * nxt_http_compress_gzip_ctx(nxt_task_t *task, nxt_http_request_t *r, nxt_http_compress_conf_t *conf) { +#if (!NXT_WITH_ZLIB) + return NULL; +#else int ret; z_stream *z; nxt_http_compress_gzip_ctx_t *ctx; @@ -114,12 +121,14 @@ nxt_http_compress_gzip_ctx(nxt_task_t *task, nxt_http_request_t *r, } return ctx; +#endif } static void nxt_http_compress_gzip_filter(nxt_task_t *task, void *obj, void *data) { +#if (NXT_WITH_ZLIB) int ret; ssize_t size; z_stream *z; @@ -180,4 +189,5 @@ fail: } return; +#endif } diff --git a/src/nxt_http_compress_gzip.h b/src/nxt_http_compress_gzip.h index 15facc69..e0c2dee2 100644 --- a/src/nxt_http_compress_gzip.h +++ b/src/nxt_http_compress_gzip.h @@ -7,6 +7,8 @@ #define NXT_HTTP_COMPRESS_GZIP_H_INCLUDED_ +#include "nxt_auto_config.h" + #include "nxt_router.h" #include "nxt_http.h" @@ -14,6 +16,13 @@ #include "nxt_types.h" +#if defined(NXT_HAVE_ZLIB) +#define NXT_WITH_ZLIB 1 +#else +#define NXT_WITH_ZLIB 0 +#endif + + nxt_int_t nxt_http_compress_gzip(nxt_task_t *task, nxt_http_request_t *r, nxt_http_compress_conf_t *conf); -- cgit