From 4071de5797da0a104b4983fc1ad393d3744b6128 Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Tue, 11 Jun 2024 00:24:28 +0100 Subject: [WIP] HTTP Compression Support --- auto/compression | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ auto/help | 4 +++ auto/options | 8 +++++ auto/sources | 16 ++++++++++ auto/summary | 3 ++ 5 files changed, 127 insertions(+) create mode 100644 auto/compression (limited to 'auto') 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 8f7553f3..0c0d0319 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 --debug enable debug logging diff --git a/auto/options b/auto/options index 0550c699..3becefb8 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_TEST_BUILD_EPOLL=NO @@ -109,6 +113,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 ;; --test-build-epoll) NXT_TEST_BUILD_EPOLL=YES ;; diff --git a/auto/sources b/auto/sources index f34d7fd7..3feafa2a 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 \ " @@ -211,6 +212,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 dd7a60a0..d7238152 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 -- cgit