This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new e244940 feat(gzip): support special * to match any type (#4817)
e244940 is described below
commit e244940ea69c00a1477e434f542fa8459d3ef302
Author: RocFang <[email protected]>
AuthorDate: Mon Aug 16 16:13:52 2021 +0800
feat(gzip): support special * to match any type (#4817)
---
apisix/plugins/gzip.lua | 30 +++++++++++++++++--------
docs/en/latest/plugins/gzip.md | 18 +++++++--------
t/plugin/gzip.t | 51 ++++++++++++++++++++++++++++++++++++++++--
3 files changed, 79 insertions(+), 20 deletions(-)
diff --git a/apisix/plugins/gzip.lua b/apisix/plugins/gzip.lua
index a226322..ac7128e 100644
--- a/apisix/plugins/gzip.lua
+++ b/apisix/plugins/gzip.lua
@@ -21,17 +21,25 @@ local req_http_version = ngx.req.http_version
local str_sub = string.sub
local ipairs = ipairs
local tonumber = tonumber
+local type = type
local schema = {
type = "object",
properties = {
types = {
- type = "array",
- minItems = 1,
- items = {
- type = "string",
- minLength = 1,
+ anyOf = {
+ {
+ type = "array",
+ minItem = 1,
+ items = {
+ type = "string",
+ minLength = 1,
+ },
+ },
+ {
+ enum = {"*"}
+ }
},
default = {"text/html"}
},
@@ -110,11 +118,15 @@ function _M.header_filter(conf, ctx)
end
local matched = false
- for _, ty in ipairs(types) do
- if content_type == ty then
- matched = true
- break
+ if type(types) == "table" then
+ for _, ty in ipairs(types) do
+ if content_type == ty then
+ matched = true
+ break
+ end
end
+ else
+ matched = true
end
if not matched then
return
diff --git a/docs/en/latest/plugins/gzip.md b/docs/en/latest/plugins/gzip.md
index a7a6af9..6a24be7 100644
--- a/docs/en/latest/plugins/gzip.md
+++ b/docs/en/latest/plugins/gzip.md
@@ -37,15 +37,15 @@ The `gzip` plugin dynamically set the gzip behavior of
Nginx.
## Attributes
-| Name | Type | Requirement | Default | Valid
| Description
|
-| --------- | ------------- | ----------- | ---------- |
------------------------------------------------------------------------ |
---------------------------------------------------------------------------------------------------------------------------------------------------
|
-| types | array | optional | ["text/html"] | |
dynamically set the `gzip_types` directive |
-| min_length | integer | optional | 20 | >= 1 |
dynamically set the `gzip_min_length` directive |
-| comp_level | integer | optional | 1 | [1, 9] |
dynamically set the `gzip_comp_level` directive |
-| http_version | number | optional | 1.1 | 1.1, 1.0 |
dynamically set the `gzip_http_version` directive |
-| buffers.number | integer | optional | 32 | >= 1 |
dynamically set the `gzip_buffers` directive |
-| buffers.size | integer | optional | 4096 | >= 1 |
dynamically set the `gzip_buffers` directive |
-| vary | boolean | optional | false | | dynamically set
the `gzip_vary` directive |
+| Name | Type | Requirement | Default | Valid
|
Description
|
+| --------------------------------------| ------------| -------------- |
-------- | --------------------------------------------------------------- |
---------------------------------------------------------------------------------------------------------------------------------------------------
|
+| types | array[string] or "*" | optional | ["text/html"] |
| dynamically set the `gzip_types` directive, special value `"*"` matches
any MIME type |
+| min_length | integer | optional | 20 | >= 1
| dynamically set the `gzip_min_length` directive |
+| comp_level | integer | optional | 1 | [1,
9] | dynamically set the `gzip_comp_level` directive |
+| http_version | number | optional | 1.1 | 1.1,
1.0 | dynamically set the `gzip_http_version` directive |
+| buffers.number | integer | optional | 32 | >= 1
| dynamically set the `gzip_buffers` directive |
+| buffers.size | integer | optional | 4096 | >= 1
| dynamically set the `gzip_buffers` directive |
+| vary | boolean | optional | false |
| dynamically set the `gzip_vary` directive |
## How To Enable
diff --git a/t/plugin/gzip.t b/t/plugin/gzip.t
index f292149..aea85e1 100644
--- a/t/plugin/gzip.t
+++ b/t/plugin/gzip.t
@@ -395,7 +395,7 @@ Content-Encoding: gzip
-=== TEST 15: vary
+=== TEST 15: match all types
--- config
location /t {
content_by_lua_block {
@@ -412,7 +412,7 @@ Content-Encoding: gzip
},
"plugins": {
"gzip": {
- "vary": true
+ "types": "*"
}
}
}]]
@@ -436,6 +436,53 @@ POST /echo
012345678
--- more_headers
Accept-Encoding: gzip
+Content-Type: video/3gpp
+--- response_headers
+Content-Encoding: gzip
+
+
+
+=== TEST 17: vary
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "uri": "/echo",
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ },
+ "plugins": {
+ "gzip": {
+ "vary": true
+ }
+ }
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+}
+--- response_body
+passed
+
+
+
+=== TEST 18: hit
+--- request
+POST /echo
+0123456789
+012345678
+--- more_headers
+Accept-Encoding: gzip
Vary: upstream
Content-Type: text/html
--- response_headers