Skip to content

Commit

Permalink
feat(core): add ngx_brotli module (#12367)
Browse files Browse the repository at this point in the history
add ngx_brotli module to Kong prebuilt Nginx binary. So we can use these configs in kong configure to support brotli compression feature in Kong.

```
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"
```

KAG-2477
  • Loading branch information
oowl committed Jan 19, 2024
1 parent f0ba930 commit 25851ba
Show file tree
Hide file tree
Showing 18 changed files with 101 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .requirements
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions build/openresty/BUILD.openresty.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions build/openresty/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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\")")
Expand Down
3 changes: 3 additions & 0 deletions changelog/unreleased/kong/add_ngx_brotli_module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: add ngx_brotli module to kong prebuild nginx
type: feature
scope: Core
1 change: 1 addition & 0 deletions scripts/explain_manifest/fixtures/amazonlinux-2-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions scripts/explain_manifest/fixtures/debian-10-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions scripts/explain_manifest/fixtures/debian-11-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions scripts/explain_manifest/fixtures/debian-12-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions scripts/explain_manifest/fixtures/el7-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions scripts/explain_manifest/fixtures/el8-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions scripts/explain_manifest/fixtures/el9-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions scripts/explain_manifest/fixtures/el9-arm64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions scripts/explain_manifest/fixtures/ubuntu-20.04-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions scripts/explain_manifest/fixtures/ubuntu-22.04-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions scripts/explain_manifest/fixtures/ubuntu-22.04-arm64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
67 changes: 67 additions & 0 deletions spec/02-integration/05-proxy/34-proxy_with_compress_spec.lua
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 25851ba

Please sign in to comment.