You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/08/25 09:50:22 UTC

[GitHub] [apisix] spacewander opened a new pull request, #7794: feat(response-rewrite): support adding header

spacewander opened a new pull request, #7794:
URL: https://github.com/apache/apisix/pull/7794

   See https://lists.apache.org/thread/bxl0sn1qb5fchvnynz7b8sst9r07cyqm
   Signed-off-by: spacewander <sp...@gmail.com>
   
   ### Description
   
   <!-- Please include a summary of the change and which issue is fixed. -->
   <!-- Please also include relevant motivation and context. -->
   
   Fixes #7776
   
   ### Checklist
   
   - [ ] I have explained the need for this PR and the problem it solves
   - [x] I have explained the changes or the new features added to this PR
   - [x] I have added tests corresponding to this change
   - [x] I have updated the documentation to reflect this change
   - [ ] I have verified that this change is backward compatible (If not, please discuss on the [APISIX mailing list](https://github.com/apache/apisix/tree/master#community) first)
   
   <!--
   
   Note
   
   1. Mark the PR as draft until it's ready to be reviewed.
   2. Always add/update tests for any changes unless you have a good reason.
   3. Always update the documentation to reflect the changes made in the PR.
   4. Make a new commit to resolve conversations instead of `push -f`.
   5. To resolve merge conflicts, merge master instead of rebasing.
   6. Use "request review" to notify the reviewer after making changes.
   7. Only a reviewer can mark a conversation as resolved.
   
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] soulbird commented on a diff in pull request #7794: feat(response-rewrite): support adding header

Posted by GitBox <gi...@apache.org>.
soulbird commented on code in PR #7794:
URL: https://github.com/apache/apisix/pull/7794#discussion_r955796770


##########
docs/zh/latest/plugins/response-rewrite.md:
##########
@@ -44,18 +44,22 @@ description: 本文介绍了关于 Apache APISIX `response-rewrite` 插件的基
 
 ## 属性
 
-| 名称              | 类型      | 必选项 | 默认值    | 有效值             | 描述                                                                                                                                                             |
-|-----------------|---------|-----|--------|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| status_code     | integer | 否  |        | [200, 598]      | 修改上游返回状态码,默认保留原始响应代码。                                                                                                                                          |
-| body            | string  | 否  |        |                 | 修改上游返回的 `body` 内容,如果设置了新内容,header 里面的 content-length 字段也会被去掉。                                                                                                  |
-| body_base64     | boolean | 否  | false  |                 | 描述 `body` 字段是否需要 base64 解码之后再返回给客户端,用在某些图片和 Protobuffer 场景。                                                                                                    |
-| headers         | object  | 否  |        |                 | 返回给客户端的 `headers`,这里可以设置多个。头信息如果存在将重写,不存在则添加。想要删除某个 header 的话,把对应的值设置为空字符串即可。这个值能够以 `$var` 的格式包含 NGINX 变量,比如 `$remote_addr $balancer_ip`。                      |
-| vars            | array[] | 否  |        |                 | `vars` 是一个表达式列表,只有满足条件的请求和响应才会修改 body 和 header 信息,来自 [lua-resty-expr](https://github.com/api7/lua-resty-expr#operator-list)。如果 `vars` 字段为空,那么所有的重写动作都会被无条件的执行。 |
-| filters         | array[] | 否  |        |                 | 一组过滤器,采用指定字符串表达式修改响应体。                                                                                                                                         |
-| filters.regex   | string  | 是  |        |                 | 用于匹配响应体正则表达式。                                                                                                               |
-| filters.scope   | string  | 否  | "once" | "once","global" | 替换范围,"once" 表达式 `filters.regex` 仅替换首次匹配上响应体的内容,"global" 则进行全局替换。                                                                                               |
-| filters.replace | string  | 是  |        |                 | 替换后的内容。                                                                                                                                                        |
-| filters.options | string  | 否  | "jo"   |                 | 正则匹配有效参数,可选项见 [ngx.re.match](https://github.com/openresty/lua-nginx-module#ngxrematch)。                                                                                                           |
+| 名称            | 类型    | 必选项 | 默认值 | 有效值          | 描述                                                                                                                                                                                                                      |
+|-----------------|---------|--------|--------|-----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| status_code     | integer | 否     |        | [200, 598]      | 修改上游返回状态码,默认保留原始响应代码。                                                                                                                                                                                |
+| body            | string  | 否     |        |                 | 修改上游返回的 `body` 内容,如果设置了新内容,header 里面的 content-length 字段也会被去掉。                                                                                                                               |
+| body_base64     | boolean | 否     | false  |                 | 描述 `body` 字段是否需要 base64 解码之后再返回给客户端,用在某些图片和 Protobuffer 场景。                                                                                                                                 |
+| headers         | object  | 否     |        |                 |                                                                                                                                                                                                                           |
+| headers.add     | array   | 否     |        |                 | 添加新的响应头。格式为 `["name: value", ...]`。这个值能够以 `$var` 的格式包含 NGINX 变量,比如 `$remote_addr $balancer_ip`。                                                                                              |
+| headers.set     | object  | 否     |        |                 | 改写响应头。格式为 `{"name": "value", ...}`。这个值能够以 `$var` 的格式包含 NGINX 变量,比如 `$remote_addr $balancer_ip`。                                                                                                |
+| headers.remove  | array   | 否     |        |                 | 移除响应头。格式为 `["name", ...]`。                                                                                                                                                                                      |
+| headers         | object  | 否     |        |                 | 返回给客户端的 `headers`,这里可以设置多个。头信息如果存在将重写,不存在则添加。想要删除某个 header 的话,把对应的值设置为空字符串即可。                                                                                  |

Review Comment:
   repeated?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] spacewander commented on a diff in pull request #7794: feat(response-rewrite): support adding header

Posted by GitBox <gi...@apache.org>.
spacewander commented on code in PR #7794:
URL: https://github.com/apache/apisix/pull/7794#discussion_r955938962


##########
apisix/plugins/response-rewrite.lua:
##########
@@ -27,13 +28,63 @@ local type        = type
 local pcall       = pcall
 
 
+local lrucache = core.lrucache.new({
+    type = "plugin",
+})
+
 local schema = {
     type = "object",
     properties = {
         headers = {
             description = "new headers for response",
-            type = "object",
-            minProperties = 1,
+            anyOf = {
+                {
+                    type = "object",
+                    minProperties = 1,
+                    patternProperties = {
+                        ["^[^:]+$"] = {
+                            oneOf = {
+                                {type = "string"},
+                                {type = "number"},
+                            }
+                        }
+                    },
+                },
+                {
+                    properties = {
+                        add = {
+                            type = "array",
+                            minItems = 1,
+                            items = {
+                                type = "string",
+                                -- "Set-Cookie: <cookie-name>=<cookie-value>; Max-Age=<number>"
+                                pattern = "^[^:]+:[^:]+[^/]$"
+                            }
+                        },
+                        set = {

Review Comment:
   For two reasons:
   1. the previous configuration works as `set` and it is an object too
   2. the `set` is unique - if two headers have the same name, only one is configured.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] spacewander commented on a diff in pull request #7794: feat(response-rewrite): support adding header

Posted by GitBox <gi...@apache.org>.
spacewander commented on code in PR #7794:
URL: https://github.com/apache/apisix/pull/7794#discussion_r955818603


##########
t/plugin/response-rewrite2.t:
##########
@@ -517,3 +517,181 @@ passed
 GET /hello
 --- response_body
 hello world
+
+
+
+=== TEST 19: schema check for headers
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            for _, case in ipairs({
+                {add = {
+                    {"headers:"}
+                }},
+                {remove = {
+                    {"headers:"}
+                }},
+                {set = {
+                    {"headers"}
+                }},
+                {set = {
+                    {[""] = 1}
+                }},
+                {set = {
+                    {["a"] = true}
+                }},
+            }) do
+                local plugin = require("apisix.plugins.response-rewrite")
+                local ok, err = plugin.check_schema({headers = case})
+                if not ok then
+                    ngx.say(err)
+                else
+                    ngx.say("done")
+                end
+            end
+    }
+}
+--- response_body eval
+"property \"headers\" validation failed: object matches none of the required\n" x 5
+
+
+
+=== TEST 20: add headers
+--- 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,
+                 [[{
+                    "plugins": {
+                        "response-rewrite": {
+                            "headers": {
+                                "add": [
+                                    "Cache-Control: no-cache",
+                                    "Cache-Control : max-age=0, must-revalidate"
+                                ]
+                            }
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uris": ["/hello"]
+                }]]
+                )
+
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 21: hit
+--- request
+GET /hello
+--- response_headers
+Cache-Control: no-cache, max-age=0, must-revalidate
+
+
+
+=== TEST 22: set headers
+--- 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,
+                 [[{
+                    "plugins": {
+                        "response-rewrite": {
+                            "headers": {
+                                "add": [
+                                    "Cache-Control: no-cache"
+                                ],
+                                "set": {
+                                    "Cache-Control": "max-age=0, must-revalidate"
+                                }
+                            }
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uris": ["/hello"]
+                }]]
+                )
+
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 23: hit
+--- request
+GET /hello
+--- response_headers
+Cache-Control: max-age=0, must-revalidate
+
+
+
+=== TEST 24: remove headers
+--- 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,
+                 [[{
+                    "plugins": {
+                        "response-rewrite": {
+                            "headers": {
+                                "add": [
+                                    "Set-Cookie: <cookie-name>=<cookie-value>; Max-Age=<number>"
+                                ],
+                                "set": {
+                                    "Cache-Control": "max-age=0, must-revalidate"
+                                },
+                                "remove": [
+                                    "Set-Cookie",
+                                    "Cache-Control"
+                                ]
+                            }
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uris": ["/hello"]
+                }]]
+                )
+
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 25: hit
+--- request
+GET /hello
+--- response_headers
+Cache-Control:
+Set-Cookie:

Review Comment:
   We usually use `name:` in `response_headers` to check the header `name` doesn't exist.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] spacewander merged pull request #7794: feat(response-rewrite): support adding header

Posted by GitBox <gi...@apache.org>.
spacewander merged PR #7794:
URL: https://github.com/apache/apisix/pull/7794


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] soulbird commented on a diff in pull request #7794: feat(response-rewrite): support adding header

Posted by GitBox <gi...@apache.org>.
soulbird commented on code in PR #7794:
URL: https://github.com/apache/apisix/pull/7794#discussion_r955794646


##########
apisix/plugins/response-rewrite.lua:
##########
@@ -235,19 +343,28 @@ function _M.header_filter(conf, ctx)
         return
     end
 
-    --reform header from object into array, so can avoid use pairs, which is NYI
-    if not conf.headers_arr then
-        conf.headers_arr = {}
+    local hdr_op, err = core.lrucache.plugin_ctx(lrucache, ctx, nil,
+                                                 create_header_operation, conf.headers)
+    if not hdr_op then
+        core.log.error("failed to create header operation: ", err)
+        return
+    end
 
-        for field, value in pairs(conf.headers) do
-            core.table.insert_tail(conf.headers_arr, field, value)
-        end
+    local field_cnt = #hdr_op.add
+    for i = 1, field_cnt, 2 do
+        local val = core.utils.resolve_var(hdr_op.add[i+1], ctx.var)
+        ngx_resp.add_header(hdr_op.add[i], val)
     end
 
-    local field_cnt = #conf.headers_arr
+    local field_cnt = #hdr_op.set
     for i = 1, field_cnt, 2 do
-        local val = core.utils.resolve_var(conf.headers_arr[i+1], ctx.var)
-        ngx.header[conf.headers_arr[i]] = val
+        local val = core.utils.resolve_var(hdr_op.set[i+1], ctx.var)
+        ngx.header[hdr_op.set[i]] = val

Review Comment:
   `core.response.set_header` ?



##########
apisix/plugins/response-rewrite.lua:
##########
@@ -235,19 +343,28 @@ function _M.header_filter(conf, ctx)
         return
     end
 
-    --reform header from object into array, so can avoid use pairs, which is NYI
-    if not conf.headers_arr then
-        conf.headers_arr = {}
+    local hdr_op, err = core.lrucache.plugin_ctx(lrucache, ctx, nil,
+                                                 create_header_operation, conf.headers)
+    if not hdr_op then
+        core.log.error("failed to create header operation: ", err)
+        return
+    end
 
-        for field, value in pairs(conf.headers) do
-            core.table.insert_tail(conf.headers_arr, field, value)
-        end
+    local field_cnt = #hdr_op.add
+    for i = 1, field_cnt, 2 do
+        local val = core.utils.resolve_var(hdr_op.add[i+1], ctx.var)
+        ngx_resp.add_header(hdr_op.add[i], val)

Review Comment:
   Can we use `core.response.add_header` ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] soulbird commented on a diff in pull request #7794: feat(response-rewrite): support adding header

Posted by GitBox <gi...@apache.org>.
soulbird commented on code in PR #7794:
URL: https://github.com/apache/apisix/pull/7794#discussion_r955816806


##########
t/plugin/response-rewrite2.t:
##########
@@ -517,3 +517,181 @@ passed
 GET /hello
 --- response_body
 hello world
+
+
+
+=== TEST 19: schema check for headers
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            for _, case in ipairs({
+                {add = {
+                    {"headers:"}
+                }},
+                {remove = {
+                    {"headers:"}
+                }},
+                {set = {
+                    {"headers"}
+                }},
+                {set = {
+                    {[""] = 1}
+                }},
+                {set = {
+                    {["a"] = true}
+                }},
+            }) do
+                local plugin = require("apisix.plugins.response-rewrite")
+                local ok, err = plugin.check_schema({headers = case})
+                if not ok then
+                    ngx.say(err)
+                else
+                    ngx.say("done")
+                end
+            end
+    }
+}
+--- response_body eval
+"property \"headers\" validation failed: object matches none of the required\n" x 5
+
+
+
+=== TEST 20: add headers
+--- 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,
+                 [[{
+                    "plugins": {
+                        "response-rewrite": {
+                            "headers": {
+                                "add": [
+                                    "Cache-Control: no-cache",
+                                    "Cache-Control : max-age=0, must-revalidate"
+                                ]
+                            }
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uris": ["/hello"]
+                }]]
+                )
+
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 21: hit
+--- request
+GET /hello
+--- response_headers
+Cache-Control: no-cache, max-age=0, must-revalidate
+
+
+
+=== TEST 22: set headers
+--- 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,
+                 [[{
+                    "plugins": {
+                        "response-rewrite": {
+                            "headers": {
+                                "add": [
+                                    "Cache-Control: no-cache"
+                                ],
+                                "set": {
+                                    "Cache-Control": "max-age=0, must-revalidate"
+                                }
+                            }
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uris": ["/hello"]
+                }]]
+                )
+
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 23: hit
+--- request
+GET /hello
+--- response_headers
+Cache-Control: max-age=0, must-revalidate
+
+
+
+=== TEST 24: remove headers
+--- 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,
+                 [[{
+                    "plugins": {
+                        "response-rewrite": {
+                            "headers": {
+                                "add": [
+                                    "Set-Cookie: <cookie-name>=<cookie-value>; Max-Age=<number>"
+                                ],
+                                "set": {
+                                    "Cache-Control": "max-age=0, must-revalidate"
+                                },
+                                "remove": [
+                                    "Set-Cookie",
+                                    "Cache-Control"
+                                ]
+                            }
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uris": ["/hello"]
+                }]]
+                )
+
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 25: hit
+--- request
+GET /hello
+--- response_headers
+Cache-Control:
+Set-Cookie:

Review Comment:
   Shouldn't these two response headers appear? instead of just the value being null.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] soulbird commented on a diff in pull request #7794: feat(response-rewrite): support adding header

Posted by GitBox <gi...@apache.org>.
soulbird commented on code in PR #7794:
URL: https://github.com/apache/apisix/pull/7794#discussion_r955820879


##########
t/plugin/response-rewrite2.t:
##########
@@ -517,3 +517,181 @@ passed
 GET /hello
 --- response_body
 hello world
+
+
+
+=== TEST 19: schema check for headers
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            for _, case in ipairs({
+                {add = {
+                    {"headers:"}
+                }},
+                {remove = {
+                    {"headers:"}
+                }},
+                {set = {
+                    {"headers"}
+                }},
+                {set = {
+                    {[""] = 1}
+                }},
+                {set = {
+                    {["a"] = true}
+                }},
+            }) do
+                local plugin = require("apisix.plugins.response-rewrite")
+                local ok, err = plugin.check_schema({headers = case})
+                if not ok then
+                    ngx.say(err)
+                else
+                    ngx.say("done")
+                end
+            end
+    }
+}
+--- response_body eval
+"property \"headers\" validation failed: object matches none of the required\n" x 5
+
+
+
+=== TEST 20: add headers
+--- 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,
+                 [[{
+                    "plugins": {
+                        "response-rewrite": {
+                            "headers": {
+                                "add": [
+                                    "Cache-Control: no-cache",
+                                    "Cache-Control : max-age=0, must-revalidate"
+                                ]
+                            }
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uris": ["/hello"]
+                }]]
+                )
+
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 21: hit
+--- request
+GET /hello
+--- response_headers
+Cache-Control: no-cache, max-age=0, must-revalidate
+
+
+
+=== TEST 22: set headers
+--- 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,
+                 [[{
+                    "plugins": {
+                        "response-rewrite": {
+                            "headers": {
+                                "add": [
+                                    "Cache-Control: no-cache"
+                                ],
+                                "set": {
+                                    "Cache-Control": "max-age=0, must-revalidate"
+                                }
+                            }
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uris": ["/hello"]
+                }]]
+                )
+
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 23: hit
+--- request
+GET /hello
+--- response_headers
+Cache-Control: max-age=0, must-revalidate
+
+
+
+=== TEST 24: remove headers
+--- 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,
+                 [[{
+                    "plugins": {
+                        "response-rewrite": {
+                            "headers": {
+                                "add": [
+                                    "Set-Cookie: <cookie-name>=<cookie-value>; Max-Age=<number>"
+                                ],
+                                "set": {
+                                    "Cache-Control": "max-age=0, must-revalidate"
+                                },
+                                "remove": [
+                                    "Set-Cookie",
+                                    "Cache-Control"
+                                ]
+                            }
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uris": ["/hello"]
+                }]]
+                )
+
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 25: hit
+--- request
+GET /hello
+--- response_headers
+Cache-Control:
+Set-Cookie:

Review Comment:
   Is this the rule for test-nginx? Got it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] tokers commented on a diff in pull request #7794: feat(response-rewrite): support adding header

Posted by GitBox <gi...@apache.org>.
tokers commented on code in PR #7794:
URL: https://github.com/apache/apisix/pull/7794#discussion_r955862458


##########
apisix/plugins/response-rewrite.lua:
##########
@@ -27,13 +28,63 @@ local type        = type
 local pcall       = pcall
 
 
+local lrucache = core.lrucache.new({
+    type = "plugin",
+})
+
 local schema = {
     type = "object",
     properties = {
         headers = {
             description = "new headers for response",
-            type = "object",
-            minProperties = 1,
+            anyOf = {
+                {
+                    type = "object",
+                    minProperties = 1,
+                    patternProperties = {
+                        ["^[^:]+$"] = {
+                            oneOf = {
+                                {type = "string"},
+                                {type = "number"},
+                            }
+                        }
+                    },
+                },
+                {
+                    properties = {
+                        add = {
+                            type = "array",
+                            minItems = 1,
+                            items = {
+                                type = "string",
+                                -- "Set-Cookie: <cookie-name>=<cookie-value>; Max-Age=<number>"
+                                pattern = "^[^:]+:[^:]+[^/]$"
+                            }
+                        },
+                        set = {

Review Comment:
   `add` and `remove` are arrays but why `set` is an object?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org