From c9b2ecd28407538d3ef0b48bba944440695196ed Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Wed, 20 Nov 2024 16:47:06 +0000 Subject: http: Wire up HTTP compression to the build system This allows to actually build unit with support for zlib, zstd and brotli compression. Any or all can be specified. E.g. $ ./configure --zlib ... $ ./configure --zlib --zstd --brotli ... During configure you will see if support for the requested compressions has been found and what version of the library is being used. E.g. ... checking for zlib ... found + zlib version: 1.3.1.zlib-ng checking for zstd ... found + zstd version: 1.5.6 checking for brotli ... found + brotli version: 1.1.0 ... Unit configuration summary: ... zlib support: .............. YES zstd support: .............. YES brotli support: ............ YES ... Co-authored-by: Alejandro Colomar Signed-off-by: Alejandro Colomar Signed-off-by: Andrew Clayton --- auto/compression | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ auto/help | 4 +++ auto/options | 8 +++++ auto/sources | 16 ++++++++++ auto/summary | 3 ++ configure | 7 +++-- 6 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 auto/compression diff --git a/auto/compression b/auto/compression new file mode 100644 index 00000000..684242f2 --- /dev/null +++ b/auto/compression @@ -0,0 +1,96 @@ + +# Copyright (C) Alejandro Colomar +# Copyright (C) Andrew Clayton +# Copyright (C) NGINX, Inc. + + +NXT_HAVE_ZLIB=no +NXT_ZLIB_CFLAGS= +NXT_ZLIB_LIBS= + +NXT_HAVE_ZSTD=no +NXT_ZSTD_CFLAGS= +NXT_ZSTD_LIBS= + +NXT_HAVE_BROTLI=no +NXT_BROTLI_CFLAGS= +NXT_BROTLI_LIBS= + + +if [ $NXT_ZLIB = YES ]; then + NXT_ZLIB_CFLAGS="$(pkgconf --cflags-only-I zlib 2>/dev/null || echo "")" + NXT_ZLIB_LIBS="$(pkgconf --libs zlib 2>/dev/null || echo "-lz")" + + 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 + echo " + zlib version: $(pkgconf --modversion zlib)" + fi +fi + + +if [ $NXT_ZSTD = YES ]; then + NXT_ZSTD_CFLAGS="$(pkgconf --cflags-only-I libzstd 2>/dev/null || echo "")" + NXT_ZSTD_LIBS="$(pkgconf --libs libzstd 2>/dev/null || echo "-lzstd")" + + nxt_feature="zstd" + nxt_feature_name=NXT_HAVE_ZSTD + nxt_feature_run=no + nxt_feature_incs=$NXT_ZSTD_CFLAGS + nxt_feature_libs=$NXT_ZSTD_LIBS + nxt_feature_test="#include + + #include + + int main(void) { + printf(\"zstd version: %u\n\", ZSTD_versionNumber()); + return 0; + }" + . auto/feature + + if [ $nxt_found = yes ]; then + NXT_HAVE_ZSTD=YES + echo " + zstd version: $(pkgconf --modversion libzstd)" + fi +fi + + +if [ $NXT_BROTLI = YES ]; then + NXT_BROTLI_CFLAGS="$(pkgconf --cflags-only-I libbrotlienc 2>/dev/null || echo "")" + NXT_BROTLI_LIBS="$(pkgconf --libs libbrotlienc 2>/dev/null || echo "-lbrotlienc")" + + nxt_feature="brotli" + nxt_feature_name=NXT_HAVE_BROTLI + nxt_feature_run=no + nxt_feature_incs=$NXT_BROTLI_CFLAGS + nxt_feature_libs=$NXT_BROTLI_LIBS + nxt_feature_test="#include + + #include + + int main(void) { + printf(\"brotli version: %d\n\", + BrotliEncoderVersion()); + return 0; + }" + . auto/feature + + if [ $nxt_found = yes ]; then + NXT_HAVE_BROTLI=YES + echo " + brotli version: $(pkgconf --modversion libbrotlienc)" + fi +fi diff --git a/auto/help b/auto/help index 94854762..1093256d 100644 --- a/auto/help +++ b/auto/help @@ -50,6 +50,10 @@ cat << END --openssl enable OpenSSL library usage + --zlib enable zlib compression + --zstd enable zstd compression + --brotli enable brotli compression + --njs enable njs library usage --otel enable otel library usage diff --git a/auto/options b/auto/options index 7aa7a73a..f1994858 100644 --- a/auto/options +++ b/auto/options @@ -26,6 +26,10 @@ NXT_GNUTLS=NO NXT_CYASSL=NO NXT_POLARSSL=NO +NXT_ZLIB=NO +NXT_ZSTD=NO +NXT_BROTLI=NO + NXT_NJS=NO NXT_OTEL=NO @@ -112,6 +116,10 @@ do --cyassl) NXT_CYASSL=YES ;; --polarssl) NXT_POLARSSL=YES ;; + --zlib) NXT_ZLIB=YES ;; + --zstd) NXT_ZSTD=YES ;; + --brotli) NXT_BROTLI=YES ;; + --njs) NXT_NJS=YES ;; --otel) NXT_OTEL=YES ;; diff --git a/auto/sources b/auto/sources index 02740397..28cdc834 100644 --- a/auto/sources +++ b/auto/sources @@ -107,6 +107,7 @@ NXT_LIB_SRCS=" \ src/nxt_http_websocket.c \ src/nxt_h1proto_websocket.c \ src/nxt_fs.c \ + src/nxt_http_compression.c \ " @@ -215,6 +216,21 @@ if [ $NXT_POLARSSL = YES ]; then fi +if [ "$NXT_HAVE_ZLIB" = "YES" ]; then + NXT_LIB_SRCS="$NXT_LIB_SRCS src/nxt_zlib.c" +fi + + +if [ "$NXT_HAVE_ZSTD" = "YES" ]; then + NXT_LIB_SRCS="$NXT_LIB_SRCS src/nxt_zstd.c" +fi + + +if [ "$NXT_HAVE_BROTLI" = "YES" ]; then + NXT_LIB_SRCS="$NXT_LIB_SRCS src/nxt_brotli.c" +fi + + if [ "$NXT_REGEX" = "YES" ]; then if [ "$NXT_HAVE_PCRE2" = "YES" ]; then NXT_LIB_SRCS="$NXT_LIB_SRCS $NXT_LIB_PCRE2_SRCS" diff --git a/auto/summary b/auto/summary index eba88be4..4a0888a6 100644 --- a/auto/summary +++ b/auto/summary @@ -28,6 +28,9 @@ Unit configuration summary: IPv6 support: .............. $NXT_INET6 Unix domain sockets support: $NXT_UNIX_DOMAIN TLS support: ............... $NXT_OPENSSL + zlib support: .............. $NXT_ZLIB + zstd support: .............. $NXT_ZSTD + brotli support: ............ $NXT_BROTLI Regex support: ............. $NXT_REGEX njs support: ............... $NXT_NJS otel support: .............. $NXT_OTEL diff --git a/configure b/configure index 05a992ee..aba56e8a 100755 --- a/configure +++ b/configure @@ -127,6 +127,7 @@ NXT_LIBRT= . auto/unix . auto/os/conf . auto/ssltls +. auto/compression if [ $NXT_REGEX = YES ]; then . auto/pcre @@ -169,11 +170,13 @@ END NXT_LIB_AUX_CFLAGS="$NXT_OPENSSL_CFLAGS $NXT_GNUTLS_CFLAGS \\ $NXT_CYASSL_CFLAGS $NXT_POLARSSL_CFLAGS \\ - $NXT_PCRE_CFLAGS" + $NXT_PCRE_CFLAGS $NXT_ZLIB_CFLAGS $NXT_ZSTD_CFLAGS \\ + $NXT_BROTLI_CFLAGS" NXT_LIB_AUX_LIBS="$NXT_OPENSSL_LIBS $NXT_GNUTLS_LIBS \\ $NXT_CYASSL_LIBS $NXT_POLARSSL_LIBS \\ - $NXT_PCRE_LIB" + $NXT_PCRE_LIB $NXT_ZLIB_LIBS $NXT_ZSTD_LIBS \\ + $NXT_BROTLI_LIBS" if [ $NXT_NJS != NO ]; then . auto/njs -- cgit