Skip to content

Commit c9b2ecd

Browse files
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 <[email protected]> Signed-off-by: Alejandro Colomar <[email protected]> Signed-off-by: Andrew Clayton <[email protected]>
1 parent 804ca81 commit c9b2ecd

File tree

6 files changed

+132
-2
lines changed

6 files changed

+132
-2
lines changed

auto/compression

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
2+
# Copyright (C) Alejandro Colomar
3+
# Copyright (C) Andrew Clayton
4+
# Copyright (C) NGINX, Inc.
5+
6+
7+
NXT_HAVE_ZLIB=no
8+
NXT_ZLIB_CFLAGS=
9+
NXT_ZLIB_LIBS=
10+
11+
NXT_HAVE_ZSTD=no
12+
NXT_ZSTD_CFLAGS=
13+
NXT_ZSTD_LIBS=
14+
15+
NXT_HAVE_BROTLI=no
16+
NXT_BROTLI_CFLAGS=
17+
NXT_BROTLI_LIBS=
18+
19+
20+
if [ $NXT_ZLIB = YES ]; then
21+
NXT_ZLIB_CFLAGS="$(pkgconf --cflags-only-I zlib 2>/dev/null || echo "")"
22+
NXT_ZLIB_LIBS="$(pkgconf --libs zlib 2>/dev/null || echo "-lz")"
23+
24+
nxt_feature="zlib"
25+
nxt_feature_name=NXT_HAVE_ZLIB
26+
nxt_feature_run=no
27+
nxt_feature_incs=$NXT_ZLIB_CFLAGS
28+
nxt_feature_libs=$NXT_ZLIB_LIBS
29+
nxt_feature_test="#include <stdio.h>
30+
31+
#include <zlib.h>
32+
33+
int main(void) {
34+
puts(zlibVersion());
35+
return 0;
36+
}"
37+
. auto/feature
38+
39+
if [ $nxt_found = yes ]; then
40+
NXT_HAVE_ZLIB=YES
41+
echo " + zlib version: $(pkgconf --modversion zlib)"
42+
fi
43+
fi
44+
45+
46+
if [ $NXT_ZSTD = YES ]; then
47+
NXT_ZSTD_CFLAGS="$(pkgconf --cflags-only-I libzstd 2>/dev/null || echo "")"
48+
NXT_ZSTD_LIBS="$(pkgconf --libs libzstd 2>/dev/null || echo "-lzstd")"
49+
50+
nxt_feature="zstd"
51+
nxt_feature_name=NXT_HAVE_ZSTD
52+
nxt_feature_run=no
53+
nxt_feature_incs=$NXT_ZSTD_CFLAGS
54+
nxt_feature_libs=$NXT_ZSTD_LIBS
55+
nxt_feature_test="#include <stdio.h>
56+
57+
#include <zstd.h>
58+
59+
int main(void) {
60+
printf(\"zstd version: %u\n\", ZSTD_versionNumber());
61+
return 0;
62+
}"
63+
. auto/feature
64+
65+
if [ $nxt_found = yes ]; then
66+
NXT_HAVE_ZSTD=YES
67+
echo " + zstd version: $(pkgconf --modversion libzstd)"
68+
fi
69+
fi
70+
71+
72+
if [ $NXT_BROTLI = YES ]; then
73+
NXT_BROTLI_CFLAGS="$(pkgconf --cflags-only-I libbrotlienc 2>/dev/null || echo "")"
74+
NXT_BROTLI_LIBS="$(pkgconf --libs libbrotlienc 2>/dev/null || echo "-lbrotlienc")"
75+
76+
nxt_feature="brotli"
77+
nxt_feature_name=NXT_HAVE_BROTLI
78+
nxt_feature_run=no
79+
nxt_feature_incs=$NXT_BROTLI_CFLAGS
80+
nxt_feature_libs=$NXT_BROTLI_LIBS
81+
nxt_feature_test="#include <stdio.h>
82+
83+
#include <brotli/encode.h>
84+
85+
int main(void) {
86+
printf(\"brotli version: %d\n\",
87+
BrotliEncoderVersion());
88+
return 0;
89+
}"
90+
. auto/feature
91+
92+
if [ $nxt_found = yes ]; then
93+
NXT_HAVE_BROTLI=YES
94+
echo " + brotli version: $(pkgconf --modversion libbrotlienc)"
95+
fi
96+
fi

auto/help

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ cat << END
5050

5151
--openssl enable OpenSSL library usage
5252

53+
--zlib enable zlib compression
54+
--zstd enable zstd compression
55+
--brotli enable brotli compression
56+
5357
--njs enable njs library usage
5458

5559
--otel enable otel library usage

auto/options

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ NXT_GNUTLS=NO
2626
NXT_CYASSL=NO
2727
NXT_POLARSSL=NO
2828

29+
NXT_ZLIB=NO
30+
NXT_ZSTD=NO
31+
NXT_BROTLI=NO
32+
2933
NXT_NJS=NO
3034
NXT_OTEL=NO
3135

@@ -112,6 +116,10 @@ do
112116
--cyassl) NXT_CYASSL=YES ;;
113117
--polarssl) NXT_POLARSSL=YES ;;
114118

119+
--zlib) NXT_ZLIB=YES ;;
120+
--zstd) NXT_ZSTD=YES ;;
121+
--brotli) NXT_BROTLI=YES ;;
122+
115123
--njs) NXT_NJS=YES ;;
116124
--otel) NXT_OTEL=YES ;;
117125

auto/sources

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ NXT_LIB_SRCS=" \
107107
src/nxt_http_websocket.c \
108108
src/nxt_h1proto_websocket.c \
109109
src/nxt_fs.c \
110+
src/nxt_http_compression.c \
110111
"
111112

112113

@@ -215,6 +216,21 @@ if [ $NXT_POLARSSL = YES ]; then
215216
fi
216217

217218

219+
if [ "$NXT_HAVE_ZLIB" = "YES" ]; then
220+
NXT_LIB_SRCS="$NXT_LIB_SRCS src/nxt_zlib.c"
221+
fi
222+
223+
224+
if [ "$NXT_HAVE_ZSTD" = "YES" ]; then
225+
NXT_LIB_SRCS="$NXT_LIB_SRCS src/nxt_zstd.c"
226+
fi
227+
228+
229+
if [ "$NXT_HAVE_BROTLI" = "YES" ]; then
230+
NXT_LIB_SRCS="$NXT_LIB_SRCS src/nxt_brotli.c"
231+
fi
232+
233+
218234
if [ "$NXT_REGEX" = "YES" ]; then
219235
if [ "$NXT_HAVE_PCRE2" = "YES" ]; then
220236
NXT_LIB_SRCS="$NXT_LIB_SRCS $NXT_LIB_PCRE2_SRCS"

auto/summary

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ Unit configuration summary:
2828
IPv6 support: .............. $NXT_INET6
2929
Unix domain sockets support: $NXT_UNIX_DOMAIN
3030
TLS support: ............... $NXT_OPENSSL
31+
zlib support: .............. $NXT_ZLIB
32+
zstd support: .............. $NXT_ZSTD
33+
brotli support: ............ $NXT_BROTLI
3134
Regex support: ............. $NXT_REGEX
3235
njs support: ............... $NXT_NJS
3336
otel support: .............. $NXT_OTEL

configure

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ NXT_LIBRT=
127127
. auto/unix
128128
. auto/os/conf
129129
. auto/ssltls
130+
. auto/compression
130131

131132
if [ $NXT_REGEX = YES ]; then
132133
. auto/pcre
@@ -169,11 +170,13 @@ END
169170

170171
NXT_LIB_AUX_CFLAGS="$NXT_OPENSSL_CFLAGS $NXT_GNUTLS_CFLAGS \\
171172
$NXT_CYASSL_CFLAGS $NXT_POLARSSL_CFLAGS \\
172-
$NXT_PCRE_CFLAGS"
173+
$NXT_PCRE_CFLAGS $NXT_ZLIB_CFLAGS $NXT_ZSTD_CFLAGS \\
174+
$NXT_BROTLI_CFLAGS"
173175

174176
NXT_LIB_AUX_LIBS="$NXT_OPENSSL_LIBS $NXT_GNUTLS_LIBS \\
175177
$NXT_CYASSL_LIBS $NXT_POLARSSL_LIBS \\
176-
$NXT_PCRE_LIB"
178+
$NXT_PCRE_LIB $NXT_ZLIB_LIBS $NXT_ZSTD_LIBS \\
179+
$NXT_BROTLI_LIBS"
177180

178181
if [ $NXT_NJS != NO ]; then
179182
. auto/njs

0 commit comments

Comments
 (0)