diff --git a/.requirements b/.requirements index bd073d8d0b83..cb60c3405cb2 100644 --- a/.requirements +++ b/.requirements @@ -17,3 +17,5 @@ NGX_WASM_MODULE=a7087a37f0d423707366a694630f1e09f4c21728 WASMER=3.1.1 WASMTIME=14.0.3 V8=10.5.18 + +NGX_BROTLI=25f86f0bac1101b6512135eac5f93c49c63609e3 # v1.0.0rc diff --git a/build/openresty/BUILD.openresty.bazel b/build/openresty/BUILD.openresty.bazel index ae79fb938671..1dd2b0f476bc 100644 --- a/build/openresty/BUILD.openresty.bazel +++ b/build/openresty/BUILD.openresty.bazel @@ -168,6 +168,7 @@ CONFIGURE_OPTIONS = [ "--add-module=$$EXT_BUILD_ROOT$$/external/lua-kong-nginx-module/stream", "--add-module=$$EXT_BUILD_ROOT$$/external/lua-resty-lmdb", "--add-module=$$EXT_BUILD_ROOT$$/external/lua-resty-events", + "--add-module=$$EXT_BUILD_ROOT$$/external/ngx_brotli", ] + select({ "@kong//:aarch64-linux-anylibc-cross": [ "--crossbuild=Linux:aarch64", @@ -261,6 +262,7 @@ configure_make( "@lua-resty-lmdb//:all_srcs", "@lua-resty-events//:all_srcs", "@openresty_binding//:all_srcs", + "@ngx_brotli//:all_srcs", ] + select({ "@kong//:wasmx_flag": [ "@ngx_wasm_module//:all_srcs", diff --git a/build/openresty/repositories.bzl b/build/openresty/repositories.bzl index b493dd246fb6..98e40eb491ae 100644 --- a/build/openresty/repositories.bzl +++ b/build/openresty/repositories.bzl @@ -69,6 +69,15 @@ def openresty_repositories(): recursive_init_submodules = True, ) + maybe( + new_git_repository, + name = "ngx_brotli", + branch = KONG_VAR["NGX_BROTLI"], + remote = "https://github.com/google/ngx_brotli", + build_file_content = _NGINX_MODULE_DUMMY_FILE, + recursive_init_submodules = True, + ) + def _openresty_binding_impl(ctx): ctx.file("BUILD.bazel", _NGINX_MODULE_DUMMY_FILE) ctx.file("WORKSPACE", "workspace(name = \"openresty_patch\")") diff --git a/changelog/unreleased/kong/add_ngx_brotli_module.yml b/changelog/unreleased/kong/add_ngx_brotli_module.yml new file mode 100644 index 000000000000..1d14f0f117b5 --- /dev/null +++ b/changelog/unreleased/kong/add_ngx_brotli_module.yml @@ -0,0 +1,3 @@ +message: add ngx_brotli module to kong prebuild nginx +type: feature +scope: Core diff --git a/scripts/explain_manifest/fixtures/amazonlinux-2-amd64.txt b/scripts/explain_manifest/fixtures/amazonlinux-2-amd64.txt index b0d0b772ff03..34190b2b9247 100644 --- a/scripts/explain_manifest/fixtures/amazonlinux-2-amd64.txt +++ b/scripts/explain_manifest/fixtures/amazonlinux-2-amd64.txt @@ -201,6 +201,7 @@ - lua-kong-nginx-module/stream - lua-resty-events - lua-resty-lmdb + - ngx_brotli - ngx_wasm_module OpenSSL : OpenSSL 3.2.0 23 Nov 2023 DWARF : True diff --git a/scripts/explain_manifest/fixtures/amazonlinux-2023-amd64.txt b/scripts/explain_manifest/fixtures/amazonlinux-2023-amd64.txt index 3c348b455c87..b67b46ffebbb 100644 --- a/scripts/explain_manifest/fixtures/amazonlinux-2023-amd64.txt +++ b/scripts/explain_manifest/fixtures/amazonlinux-2023-amd64.txt @@ -187,6 +187,7 @@ - lua-kong-nginx-module/stream - lua-resty-events - lua-resty-lmdb + - ngx_brotli - ngx_wasm_module OpenSSL : OpenSSL 3.2.0 23 Nov 2023 DWARF : True diff --git a/scripts/explain_manifest/fixtures/amazonlinux-2023-arm64.txt b/scripts/explain_manifest/fixtures/amazonlinux-2023-arm64.txt index 48576d505f1f..a9f1b4faf91e 100644 --- a/scripts/explain_manifest/fixtures/amazonlinux-2023-arm64.txt +++ b/scripts/explain_manifest/fixtures/amazonlinux-2023-arm64.txt @@ -169,6 +169,7 @@ - lua-kong-nginx-module/stream - lua-resty-events - lua-resty-lmdb + - ngx_brotli - ngx_wasm_module OpenSSL : OpenSSL 3.2.0 23 Nov 2023 DWARF : True diff --git a/scripts/explain_manifest/fixtures/debian-10-amd64.txt b/scripts/explain_manifest/fixtures/debian-10-amd64.txt index 951fb52d982e..d79c02cde0f5 100644 --- a/scripts/explain_manifest/fixtures/debian-10-amd64.txt +++ b/scripts/explain_manifest/fixtures/debian-10-amd64.txt @@ -201,6 +201,7 @@ - lua-kong-nginx-module/stream - lua-resty-events - lua-resty-lmdb + - ngx_brotli - ngx_wasm_module OpenSSL : OpenSSL 3.2.0 23 Nov 2023 DWARF : True diff --git a/scripts/explain_manifest/fixtures/debian-11-amd64.txt b/scripts/explain_manifest/fixtures/debian-11-amd64.txt index 3a9420610de1..6b2c8a6327a6 100644 --- a/scripts/explain_manifest/fixtures/debian-11-amd64.txt +++ b/scripts/explain_manifest/fixtures/debian-11-amd64.txt @@ -179,6 +179,7 @@ - libpthread.so.0 - libcrypt.so.1 - libluajit-5.1.so.2 + - libm.so.6 - libssl.so.3 - libcrypto.so.3 - libz.so.1 @@ -189,6 +190,7 @@ - lua-kong-nginx-module/stream - lua-resty-events - lua-resty-lmdb + - ngx_brotli - ngx_wasm_module OpenSSL : OpenSSL 3.2.0 23 Nov 2023 DWARF : True diff --git a/scripts/explain_manifest/fixtures/debian-12-amd64.txt b/scripts/explain_manifest/fixtures/debian-12-amd64.txt index d8a45bc54db6..1db2a407276f 100644 --- a/scripts/explain_manifest/fixtures/debian-12-amd64.txt +++ b/scripts/explain_manifest/fixtures/debian-12-amd64.txt @@ -166,6 +166,7 @@ Needed : - libcrypt.so.1 - libluajit-5.1.so.2 + - libm.so.6 - libssl.so.3 - libcrypto.so.3 - libz.so.1 @@ -176,6 +177,7 @@ - lua-kong-nginx-module/stream - lua-resty-events - lua-resty-lmdb + - ngx_brotli - ngx_wasm_module OpenSSL : OpenSSL 3.2.0 23 Nov 2023 DWARF : True diff --git a/scripts/explain_manifest/fixtures/el7-amd64.txt b/scripts/explain_manifest/fixtures/el7-amd64.txt index b0d0b772ff03..34190b2b9247 100644 --- a/scripts/explain_manifest/fixtures/el7-amd64.txt +++ b/scripts/explain_manifest/fixtures/el7-amd64.txt @@ -201,6 +201,7 @@ - lua-kong-nginx-module/stream - lua-resty-events - lua-resty-lmdb + - ngx_brotli - ngx_wasm_module OpenSSL : OpenSSL 3.2.0 23 Nov 2023 DWARF : True diff --git a/scripts/explain_manifest/fixtures/el8-amd64.txt b/scripts/explain_manifest/fixtures/el8-amd64.txt index b0817c9bdc33..c0e493082a4b 100644 --- a/scripts/explain_manifest/fixtures/el8-amd64.txt +++ b/scripts/explain_manifest/fixtures/el8-amd64.txt @@ -200,6 +200,7 @@ - lua-kong-nginx-module/stream - lua-resty-events - lua-resty-lmdb + - ngx_brotli - ngx_wasm_module OpenSSL : OpenSSL 3.2.0 23 Nov 2023 DWARF : True diff --git a/scripts/explain_manifest/fixtures/el9-amd64.txt b/scripts/explain_manifest/fixtures/el9-amd64.txt index a9eb59444920..87ddaec8f707 100644 --- a/scripts/explain_manifest/fixtures/el9-amd64.txt +++ b/scripts/explain_manifest/fixtures/el9-amd64.txt @@ -187,6 +187,7 @@ - lua-kong-nginx-module/stream - lua-resty-events - lua-resty-lmdb + - ngx_brotli - ngx_wasm_module OpenSSL : OpenSSL 3.2.0 23 Nov 2023 DWARF : True diff --git a/scripts/explain_manifest/fixtures/el9-arm64.txt b/scripts/explain_manifest/fixtures/el9-arm64.txt index 48576d505f1f..a9f1b4faf91e 100644 --- a/scripts/explain_manifest/fixtures/el9-arm64.txt +++ b/scripts/explain_manifest/fixtures/el9-arm64.txt @@ -169,6 +169,7 @@ - lua-kong-nginx-module/stream - lua-resty-events - lua-resty-lmdb + - ngx_brotli - ngx_wasm_module OpenSSL : OpenSSL 3.2.0 23 Nov 2023 DWARF : True diff --git a/scripts/explain_manifest/fixtures/ubuntu-20.04-amd64.txt b/scripts/explain_manifest/fixtures/ubuntu-20.04-amd64.txt index f909b112e2af..854c2289e381 100644 --- a/scripts/explain_manifest/fixtures/ubuntu-20.04-amd64.txt +++ b/scripts/explain_manifest/fixtures/ubuntu-20.04-amd64.txt @@ -183,6 +183,7 @@ - libpthread.so.0 - libcrypt.so.1 - libluajit-5.1.so.2 + - libm.so.6 - libssl.so.3 - libcrypto.so.3 - libz.so.1 @@ -193,6 +194,7 @@ - lua-kong-nginx-module/stream - lua-resty-events - lua-resty-lmdb + - ngx_brotli - ngx_wasm_module OpenSSL : OpenSSL 3.2.0 23 Nov 2023 DWARF : True diff --git a/scripts/explain_manifest/fixtures/ubuntu-22.04-amd64.txt b/scripts/explain_manifest/fixtures/ubuntu-22.04-amd64.txt index b924206af824..8c96980a4752 100644 --- a/scripts/explain_manifest/fixtures/ubuntu-22.04-amd64.txt +++ b/scripts/explain_manifest/fixtures/ubuntu-22.04-amd64.txt @@ -170,6 +170,7 @@ Needed : - libcrypt.so.1 - libluajit-5.1.so.2 + - libm.so.6 - libssl.so.3 - libcrypto.so.3 - libz.so.1 @@ -180,6 +181,7 @@ - lua-kong-nginx-module/stream - lua-resty-events - lua-resty-lmdb + - ngx_brotli - ngx_wasm_module OpenSSL : OpenSSL 3.2.0 23 Nov 2023 DWARF : True diff --git a/scripts/explain_manifest/fixtures/ubuntu-22.04-arm64.txt b/scripts/explain_manifest/fixtures/ubuntu-22.04-arm64.txt index 70700de3e9ab..da9623d15a0b 100644 --- a/scripts/explain_manifest/fixtures/ubuntu-22.04-arm64.txt +++ b/scripts/explain_manifest/fixtures/ubuntu-22.04-arm64.txt @@ -167,6 +167,7 @@ Needed : - libcrypt.so.1 - libluajit-5.1.so.2 + - libm.so.6 - libssl.so.3 - libcrypto.so.3 - libz.so.1 @@ -178,6 +179,7 @@ - lua-kong-nginx-module/stream - lua-resty-events - lua-resty-lmdb + - ngx_brotli - ngx_wasm_module OpenSSL : OpenSSL 3.2.0 23 Nov 2023 DWARF : True diff --git a/spec/02-integration/05-proxy/34-proxy_with_compress_spec.lua b/spec/02-integration/05-proxy/34-proxy_with_compress_spec.lua new file mode 100644 index 000000000000..ed266acbc9a2 --- /dev/null +++ b/spec/02-integration/05-proxy/34-proxy_with_compress_spec.lua @@ -0,0 +1,67 @@ +local helpers = require "spec.helpers" + +for _, strategy in helpers.each_strategy() do + describe("Proxy with compressor [#" .. strategy .. "]", function() + + describe("[http] brotli", function() + local proxy_client + local proxy_ssl_client + lazy_setup(function() + local bp = helpers.get_db_utils(strategy, { + "routes", + "services", + "plugins", + }) + + local s0 = bp.services:insert { + name = "service0", + } + + bp.routes:insert { + paths = { "/0" }, + service = s0, + } + + assert(helpers.start_kong({ + database = strategy, + nginx_conf = "spec/fixtures/custom_nginx.template", + nginx_proxy_brotli = "on", + nginx_proxy_brotli_comp_level = 6, + nginx_proxy_brotli_types = "text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js", + stream_listen = "off", + admin_listen = "off", + })) + end) + + lazy_teardown(function() + helpers.stop_kong() + end) + + before_each(function() + proxy_client = helpers.proxy_client() + proxy_ssl_client = helpers.proxy_ssl_client() + end) + + after_each(function() + if proxy_client then + proxy_client:close() + end + + if proxy_ssl_client then + proxy_ssl_client:close() + end + end) + + it("header can be set when brotli compressor works fine", function() + local res = proxy_client:get("/0/xml", { + headers = { + ["Accept-Encoding"] = "br", + ["Content-Type"] = "application/xml", + } + }) + assert.res_status(200, res) + assert.equal("br", res.headers["Content-Encoding"]) + end) + end) + end) +end