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/11/16 03:38:59 UTC

[GitHub] [apisix] mscb402 opened a new pull request, #8336: feat: proxy-rewrite support config add set and remove header

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

   ### Description
   
   Fixes #8239 
   
   ### Checklist
   
   - [x] 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
   - [x] 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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
t/plugin/proxy-rewrite3.t:
##########
@@ -337,3 +337,145 @@ X-Forwarded-Host: apisix.ai
 X-Forwarded-Host: test.com
 --- no_error_log
 [error]
+
+
+
+=== TEST 14: set route header test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "123"},
+                                    "set":{"test2": "2233"},
+                                    "remove":["hello"]
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 15: add exist header in muti-header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+test: bbb
+--- response_headers
+test: sssss, bbb, 123

Review Comment:
   done @spacewander 



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
docs/en/latest/plugins/proxy-rewrite.md:
##########
@@ -39,7 +39,10 @@ The `proxy-rewrite` Plugin rewrites Upstream proxy information such as `scheme`,
 | method                      | string        | False    |         | ["GET", "POST", "PUT", "HEAD", "DELETE", "OPTIONS","MKCOL", "COPY", "MOVE", "PROPFIND", "PROPFIND","LOCK", "UNLOCK", "PATCH", "TRACE"] | Rewrites the HTTP method.                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
 | regex_uri                   | array[string] | False    |         |                                                                                                                                        | New upstream forwarding address. Regular expressions can be used to match the URL from client. If it matches, the URL template is forwarded to the Upstream otherwise, the URL from the client is forwarded. When both `uri` and `regex_uri` are configured, `uri` is used first. For example, `[" ^/iresty/(.*)/(.*)/(.*)", "/$1-$2-$3"]`. Here, the first element is the regular expression to match and the second element is the URL template forwarded to the Upstream. |
 | host                        | string        | False    |         |                                                                                                                                        | New Upstream host address.                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
-| headers                     | object        | False    |         |                                                                                                                                        | New Upstream headers. Headers are overwritten if they are already present otherwise, they are added to the present headers. To remove a header, set the header value to an empty string. The values in the header can contain Nginx variables like `$remote_addr` and `$client_addr`.                                                                                                                                                                                        |
+| headers                     | object        | False    |         |                                                                                                                                   |                   |
+| headers.add     | object   | false     |        |                 | Append the new headers. The format is `{"name: value",...}`. The values in the header can contain Nginx variables like $remote_addr and $balancer_ip.                                                                                              |
+| headers.set     | object  | false     |        |                 | Rewriting the headers. The format is  `{"name": "value", ...}`. The values in the header can contain Nginx variables like $remote_addr and $balancer_ip.                                                                                                |

Review Comment:
   This `headers.set` is the same as the response-rewrite plugin. When the header does not exist will add 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] tzssangglass commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
apisix/core/request.lua:
##########
@@ -39,6 +44,7 @@ local req_get_uri_args = ngx.req.get_uri_args
 local req_set_uri_args = ngx.req.set_uri_args
 
 
+

Review Comment:
   delete this line



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
t/plugin/proxy-rewrite3.t:
##########
@@ -337,3 +337,145 @@ X-Forwarded-Host: apisix.ai
 X-Forwarded-Host: test.com
 --- no_error_log
 [error]
+
+
+
+=== TEST 14: set route header test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "123"},
+                                    "set":{"test2": "2233"},
+                                    "remove":["hello"]
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 15: add exist header in muti-header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+test: bbb
+--- response_headers
+test: sssss, bbb, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 16: add header to exist header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+--- response_headers
+test: sssss, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 17: remove header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+hello: word
+--- response_headers
+hello:
+--- no_error_log
+[error]
+
+
+
+=== TEST 18: set header success
+--- request
+GET /echo HTTP/1.1
+--- response_headers
+test2: 2233
+--- no_error_log
+[error]
+
+
+
+=== TEST 19: header priority test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "test_in_add"},
+                                    "set":{"test": "test_in_set"}
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 20: set and test priority test
+--- request
+GET /echo HTTP/1.1
+--- response_headers
+test: test_in_set

Review Comment:
   And change `anyOf ` to `oneOf` is done



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
t/plugin/proxy-rewrite3.t:
##########
@@ -313,6 +313,57 @@ ngx.var.request_uri: /print_uri_detailed
                 }]]
                 )
 
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 13: rewrite X-Forwarded-Host

Review Comment:
   Nope, but this change is to remove duplicate sections from your advice. So I changed some test code.
   
   https://github.com/apache/apisix/pull/8336#discussion_r1026081853
   



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
apisix/core/request.lua:
##########
@@ -22,6 +22,12 @@
 local lfs = require("lfs")
 local log = require("apisix.core.log")
 local io = require("apisix.core.io")
+local ngx_req

Review Comment:
   removed



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
docs/en/latest/plugins/proxy-rewrite.md:
##########
@@ -39,7 +39,10 @@ The `proxy-rewrite` Plugin rewrites Upstream proxy information such as `scheme`,
 | method                      | string        | False    |         | ["GET", "POST", "PUT", "HEAD", "DELETE", "OPTIONS","MKCOL", "COPY", "MOVE", "PROPFIND", "PROPFIND","LOCK", "UNLOCK", "PATCH", "TRACE"] | Rewrites the HTTP method.                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
 | regex_uri                   | array[string] | False    |         |                                                                                                                                        | New upstream forwarding address. Regular expressions can be used to match the URL from client. If it matches, the URL template is forwarded to the Upstream otherwise, the URL from the client is forwarded. When both `uri` and `regex_uri` are configured, `uri` is used first. For example, `[" ^/iresty/(.*)/(.*)/(.*)", "/$1-$2-$3"]`. Here, the first element is the regular expression to match and the second element is the URL template forwarded to the Upstream. |
 | host                        | string        | False    |         |                                                                                                                                        | New Upstream host address.                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
-| headers                     | object        | False    |         |                                                                                                                                        | New Upstream headers. Headers are overwritten if they are already present otherwise, they are added to the present headers. To remove a header, set the header value to an empty string. The values in the header can contain Nginx variables like `$remote_addr` and `$client_addr`.                                                                                                                                                                                        |
+| headers                     | object        | False    |         |                                                                                                                                   |                   |
+| headers.add     | object   | false     |        |                 | Append the new headers. The format is `{"name: value",...}`. The values in the header can contain Nginx variables like $remote_addr and $balancer_ip.                                                                                              |
+| headers.set     | object  | false     |        |                 | Rewriting the headers. The format is  `{"name": "value", ...}`. The values in the header can contain Nginx variables like $remote_addr and $balancer_ip.                                                                                                |
+| headers.remove  | array   | false     |        |                 | Remove the headers. The format is `["name", ...]`.

Review Comment:
   donr



##########
docs/en/latest/plugins/proxy-rewrite.md:
##########
@@ -39,7 +39,10 @@ The `proxy-rewrite` Plugin rewrites Upstream proxy information such as `scheme`,
 | method                      | string        | False    |         | ["GET", "POST", "PUT", "HEAD", "DELETE", "OPTIONS","MKCOL", "COPY", "MOVE", "PROPFIND", "PROPFIND","LOCK", "UNLOCK", "PATCH", "TRACE"] | Rewrites the HTTP method.                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
 | regex_uri                   | array[string] | False    |         |                                                                                                                                        | New upstream forwarding address. Regular expressions can be used to match the URL from client. If it matches, the URL template is forwarded to the Upstream otherwise, the URL from the client is forwarded. When both `uri` and `regex_uri` are configured, `uri` is used first. For example, `[" ^/iresty/(.*)/(.*)/(.*)", "/$1-$2-$3"]`. Here, the first element is the regular expression to match and the second element is the URL template forwarded to the Upstream. |
 | host                        | string        | False    |         |                                                                                                                                        | New Upstream host address.                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
-| headers                     | object        | False    |         |                                                                                                                                        | New Upstream headers. Headers are overwritten if they are already present otherwise, they are added to the present headers. To remove a header, set the header value to an empty string. The values in the header can contain Nginx variables like `$remote_addr` and `$client_addr`.                                                                                                                                                                                        |
+| headers                     | object        | False    |         |                                                                                                                                   |                   |
+| headers.add     | object   | false     |        |                 | Append the new headers. The format is `{"name: value",...}`. The values in the header can contain Nginx variables like $remote_addr and $balancer_ip.                                                                                              |
+| headers.set     | object  | false     |        |                 | Rewriting the headers. The format is  `{"name": "value", ...}`. The values in the header can contain Nginx variables like $remote_addr and $balancer_ip.                                                                                                |
+| headers.remove  | array   | false     |        |                 | Remove the headers. The format is `["name", ...]`.

Review Comment:
   done



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
apisix/core/request.lua:
##########
@@ -138,6 +145,15 @@ function _M.set_header(ctx, header_name, header_value)
     end
 end
 
+function _M.add_header(header_name, header_value)
+    local err
+    header_name, err = _validate_header_name(header_name)
+    if err then
+        error(err)
+    end
+
+    req_add_header(header_name,header_value)

Review Comment:
   done



-- 
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 #8336: feat: proxy-rewrite support config add set and remove header

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


##########
apisix/plugins/proxy-rewrite.lua:
##########
@@ -70,8 +74,58 @@ local schema = {
         },
         headers = {
             description = "new headers for request",
-            type = "object",
-            minProperties = 1,
+            anyOf = {

Review Comment:
   @mscb402 



-- 
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 #8336: feat: proxy-rewrite support config add set and remove header

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


##########
t/plugin/proxy-rewrite3.t:
##########
@@ -337,3 +337,145 @@ X-Forwarded-Host: apisix.ai
 X-Forwarded-Host: test.com
 --- no_error_log
 [error]
+
+
+
+=== TEST 14: set route header test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "123"},
+                                    "set":{"test2": "2233"},
+                                    "remove":["hello"]
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 15: add exist header in muti-header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+test: bbb
+--- response_headers
+test: sssss, bbb, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 16: add header to exist header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+--- response_headers
+test: sssss, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 17: remove header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+hello: word
+--- response_headers
+hello:
+--- no_error_log
+[error]
+
+
+
+=== TEST 18: set header success
+--- request
+GET /echo HTTP/1.1
+--- response_headers
+test2: 2233
+--- no_error_log
+[error]
+
+
+
+=== TEST 19: header priority test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "test_in_add"},
+                                    "set":{"test": "test_in_set"}
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 20: set and test priority test
+--- request
+GET /echo HTTP/1.1
+--- response_headers
+test: test_in_set

Review Comment:
   I just reviewed the code and now I know that `add` runs before than `set`. What we want to is writing the running priority between these operations. Then users can evaluate if this is expected.



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
t/plugin/proxy-rewrite3.t:
##########
@@ -328,12 +379,95 @@ passed
 
 
 
-=== TEST 13: rewrite X-Forwarded-Host
+=== TEST 15: add exist header in muti-header
 --- request
 GET /echo HTTP/1.1
 --- more_headers
-X-Forwarded-Host: apisix.ai
+test: sssss
+test: bbb
 --- response_headers
-X-Forwarded-Host: test.com
+test: sssss, bbb, 123
+--- no_error_log

Review Comment:
   done



-- 
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] tzssangglass commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
apisix/plugins/proxy-rewrite.lua:
##########
@@ -150,13 +220,69 @@ do
         core.table.insert(upstream_names, name)
     end
 
-function _M.rewrite(conf, ctx)
-    for _, name in ipairs(upstream_names) do
-        if conf[name] then
-            ctx.var[upstream_vars[name]] = conf[name]
+    local function create_header_operation(hdr_conf)
+        local set = {}
+        local add = {}
+
+        if is_new_headers_conf(hdr_conf) then
+            if hdr_conf.add then
+                for field, value in pairs(hdr_conf.add) do
+                    core.table.insert_tail(add, field, value)
+                end
+            end
+            if hdr_conf.set then
+                for field, value in pairs(hdr_conf.set) do
+                    core.table.insert_tail(set, field, value)
+                end
+            end
+
+        else
+            for field, value in pairs(hdr_conf) do
+                core.table.insert_tail(set, field, value)
+            end
         end
+
+        return {
+            add = add,
+            set = set,
+            remove = hdr_conf.remove or {},
+        }
     end
 
+    local function addHeader(ctx, header_name, header_value)
+        local oldHeader = core.request.header(ctx, header_name)

Review Comment:
   ```suggestion
           local old_header = core.request.header(ctx, header_name)
   ```



##########
apisix/plugins/proxy-rewrite.lua:
##########
@@ -150,13 +220,69 @@ do
         core.table.insert(upstream_names, name)
     end
 
-function _M.rewrite(conf, ctx)
-    for _, name in ipairs(upstream_names) do
-        if conf[name] then
-            ctx.var[upstream_vars[name]] = conf[name]
+    local function create_header_operation(hdr_conf)
+        local set = {}
+        local add = {}
+
+        if is_new_headers_conf(hdr_conf) then
+            if hdr_conf.add then
+                for field, value in pairs(hdr_conf.add) do
+                    core.table.insert_tail(add, field, value)
+                end
+            end
+            if hdr_conf.set then
+                for field, value in pairs(hdr_conf.set) do
+                    core.table.insert_tail(set, field, value)
+                end
+            end
+
+        else
+            for field, value in pairs(hdr_conf) do
+                core.table.insert_tail(set, field, value)
+            end
         end
+
+        return {
+            add = add,
+            set = set,
+            remove = hdr_conf.remove or {},
+        }
     end
 
+    local function addHeader(ctx, header_name, header_value)

Review Comment:
   ```suggestion
       local function add_header(ctx, header_name, header_value)
   ```



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
t/plugin/proxy-rewrite3.t:
##########
@@ -337,3 +337,145 @@ X-Forwarded-Host: apisix.ai
 X-Forwarded-Host: test.com
 --- no_error_log
 [error]
+
+
+
+=== TEST 14: set route header test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "123"},
+                                    "set":{"test2": "2233"},
+                                    "remove":["hello"]
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 15: add exist header in muti-header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+test: bbb
+--- response_headers
+test: sssss, bbb, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 16: add header to exist header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+--- response_headers
+test: sssss, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 17: remove header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+hello: word
+--- response_headers
+hello:
+--- no_error_log
+[error]
+
+
+
+=== TEST 18: set header success
+--- request
+GET /echo HTTP/1.1
+--- response_headers
+test2: 2233
+--- no_error_log
+[error]
+
+
+
+=== TEST 19: header priority test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "test_in_add"},
+                                    "set":{"test": "test_in_set"}
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 20: set and test priority test
+--- request
+GET /echo HTTP/1.1
+--- response_headers
+test: test_in_set

Review Comment:
   Maybe we have different definitions of priorities. In a document, a priority represents an area of influence. The `remove` have a high priority. If you put in `remove` it will remove this header whatever you config in `set` or `add`. If you config `set` and `add` together, only `set` will process because `set` has high priority than `add`. 
   So, if in your different definitions of priorities. The priorities should be  `add` > `set` > `remove`



-- 
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 #8336: feat: proxy-rewrite support config add set and remove header

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


##########
t/plugin/proxy-rewrite3.t:
##########
@@ -337,3 +337,94 @@ X-Forwarded-Host: apisix.ai
 X-Forwarded-Host: test.com
 --- no_error_log
 [error]
+
+
+
+=== TEST 14: set route add test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "123"},
+                                    "set":{"test2": "2233"},
+                                    "remove":["hello"]
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 15: add exist header in muti-header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+test: bbb
+--- response_headers
+test: sssss, bbb, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 16: add header to exist header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+--- response_headers
+test: sssss, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 17: remove header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+hello: word
+--- response_headers
+hello:
+--- no_error_log
+[error]
+
+
+
+=
+== TEST 18: remove header success
+--- request
+GET /echo HTTP/1.1
+--- response_headers
+test2: 2233
+--- no_error_log
+[error]

Review Comment:
   Missing cases:
   
   1. The set is not used
   2. Add a case which add, set the same header, for testing the priority.



##########
docs/en/latest/plugins/proxy-rewrite.md:
##########
@@ -39,7 +39,10 @@ The `proxy-rewrite` Plugin rewrites Upstream proxy information such as `scheme`,
 | method                      | string        | False    |         | ["GET", "POST", "PUT", "HEAD", "DELETE", "OPTIONS","MKCOL", "COPY", "MOVE", "PROPFIND", "PROPFIND","LOCK", "UNLOCK", "PATCH", "TRACE"] | Rewrites the HTTP method.                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
 | regex_uri                   | array[string] | False    |         |                                                                                                                                        | New upstream forwarding address. Regular expressions can be used to match the URL from client. If it matches, the URL template is forwarded to the Upstream otherwise, the URL from the client is forwarded. When both `uri` and `regex_uri` are configured, `uri` is used first. For example, `[" ^/iresty/(.*)/(.*)/(.*)", "/$1-$2-$3"]`. Here, the first element is the regular expression to match and the second element is the URL template forwarded to the Upstream. |
 | host                        | string        | False    |         |                                                                                                                                        | New Upstream host address.                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
-| headers                     | object        | False    |         |                                                                                                                                        | New Upstream headers. Headers are overwritten if they are already present otherwise, they are added to the present headers. To remove a header, set the header value to an empty string. The values in the header can contain Nginx variables like `$remote_addr` and `$client_addr`.                                                                                                                                                                                        |
+| headers                     | object        | False    |         |                                                                                                                                   |                   |
+| headers.add     | object   | false     |        |                 | Append the new headers. The format is `{"name: value",...}`. The values in the header can contain Nginx variables like $remote_addr and $balancer_ip.                                                                                              |
+| headers.set     | object  | false     |        |                 | Rewriting the headers. The format is  `{"name": "value", ...}`. The values in the header can contain Nginx variables like $remote_addr and $balancer_ip.                                                                                                |

Review Comment:
   I think overwrite will be better than rewriting.



##########
docs/en/latest/plugins/proxy-rewrite.md:
##########
@@ -39,7 +39,10 @@ The `proxy-rewrite` Plugin rewrites Upstream proxy information such as `scheme`,
 | method                      | string        | False    |         | ["GET", "POST", "PUT", "HEAD", "DELETE", "OPTIONS","MKCOL", "COPY", "MOVE", "PROPFIND", "PROPFIND","LOCK", "UNLOCK", "PATCH", "TRACE"] | Rewrites the HTTP method.                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
 | regex_uri                   | array[string] | False    |         |                                                                                                                                        | New upstream forwarding address. Regular expressions can be used to match the URL from client. If it matches, the URL template is forwarded to the Upstream otherwise, the URL from the client is forwarded. When both `uri` and `regex_uri` are configured, `uri` is used first. For example, `[" ^/iresty/(.*)/(.*)/(.*)", "/$1-$2-$3"]`. Here, the first element is the regular expression to match and the second element is the URL template forwarded to the Upstream. |
 | host                        | string        | False    |         |                                                                                                                                        | New Upstream host address.                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
-| headers                     | object        | False    |         |                                                                                                                                        | New Upstream headers. Headers are overwritten if they are already present otherwise, they are added to the present headers. To remove a header, set the header value to an empty string. The values in the header can contain Nginx variables like `$remote_addr` and `$client_addr`.                                                                                                                                                                                        |
+| headers                     | object        | False    |         |                                                                                                                                   |                   |
+| headers.add     | object   | false     |        |                 | Append the new headers. The format is `{"name: value",...}`. The values in the header can contain Nginx variables like $remote_addr and $balancer_ip.                                                                                              |
+| headers.set     | object  | false     |        |                 | Rewriting the headers. The format is  `{"name": "value", ...}`. The values in the header can contain Nginx variables like $remote_addr and $balancer_ip.                                                                                                |
+| headers.remove  | array   | false     |        |                 | Remove the headers. The format is `["name", ...]`.

Review Comment:
   Should also tell users the priority of set, remove, and add.



-- 
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 #8336: feat: proxy-rewrite support config add set and remove header

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


##########
apisix/plugins/proxy-rewrite.lua:
##########
@@ -70,8 +74,58 @@ local schema = {
         },
         headers = {
             description = "new headers for request",
-            type = "object",
-            minProperties = 1,
+            anyOf = {

Review Comment:
   We should use `oneOf`?



##########
apisix/plugins/proxy-rewrite.lua:
##########
@@ -163,6 +163,8 @@ local function check_set_headers(headers)
         if #field == 0 then
             return false, 'invalid field length in header'
         end
+
+        core.log.info("header field: ", field)

Review Comment:
   Why not also show the value?



-- 
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] tzssangglass commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
t/plugin/proxy-rewrite3.t:
##########
@@ -337,3 +337,145 @@ X-Forwarded-Host: apisix.ai
 X-Forwarded-Host: test.com
 --- no_error_log
 [error]
+
+
+
+=== TEST 14: set route header test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "123"},
+                                    "set":{"test2": "2233"},
+                                    "remove":["hello"]
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 15: add exist header in muti-header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+test: bbb
+--- response_headers
+test: sssss, bbb, 123

Review Comment:
   why it is 
   
   ```
   test: sssss
   test: bbb
   test: 123
   ```



-- 
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 #8336: feat: proxy-rewrite support config add set and remove header

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


##########
t/plugin/proxy-rewrite3.t:
##########
@@ -328,12 +379,95 @@ passed
 
 
 
-=== TEST 13: rewrite X-Forwarded-Host
+=== TEST 15: add exist header in muti-header
 --- request
 GET /echo HTTP/1.1
 --- more_headers
-X-Forwarded-Host: apisix.ai
+test: sssss
+test: bbb
 --- response_headers
-X-Forwarded-Host: test.com
+test: sssss, bbb, 123
+--- no_error_log

Review Comment:
   Need to deal with https://github.com/apache/apisix/pull/8336#discussion_r1026081925 in other test



##########
apisix/core/request.lua:
##########
@@ -138,6 +145,15 @@ function _M.set_header(ctx, header_name, header_value)
     end
 end
 
+function _M.add_header(header_name, header_value)
+    local err
+    header_name, err = _validate_header_name(header_name)
+    if err then
+        error(err)
+    end
+
+    req_add_header(header_name,header_value)

Review Comment:
   Please ensure a space is after the ','. Let's deal with similar places in this PR.



##########
apisix/core/request.lua:
##########
@@ -22,6 +22,12 @@
 local lfs = require("lfs")
 local log = require("apisix.core.log")
 local io = require("apisix.core.io")
+local ngx_req

Review Comment:
   We don't need a ngx_req as a module variable



##########
docs/en/latest/plugins/proxy-rewrite.md:
##########
@@ -39,9 +39,18 @@ The `proxy-rewrite` Plugin rewrites Upstream proxy information such as `scheme`,
 | method                      | string        | False    |         | ["GET", "POST", "PUT", "HEAD", "DELETE", "OPTIONS","MKCOL", "COPY", "MOVE", "PROPFIND", "PROPFIND","LOCK", "UNLOCK", "PATCH", "TRACE"] | Rewrites the HTTP method.                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
 | regex_uri                   | array[string] | False    |         |                                                                                                                                        | New upstream forwarding address. Regular expressions can be used to match the URL from client. If it matches, the URL template is forwarded to the Upstream otherwise, the URL from the client is forwarded. When both `uri` and `regex_uri` are configured, `uri` is used first. For example, `[" ^/iresty/(.*)/(.*)/(.*)", "/$1-$2-$3"]`. Here, the first element is the regular expression to match and the second element is the URL template forwarded to the Upstream. |
 | host                        | string        | False    |         |                                                                                                                                        | New Upstream host address.                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
-| headers                     | object        | False    |         |                                                                                                                                        | New Upstream headers. Headers are overwritten if they are already present otherwise, they are added to the present headers. To remove a header, set the header value to an empty string. The values in the header can contain Nginx variables like `$remote_addr` and `$client_addr`.                                                                                                                                                                                        |
+| headers                     | object        | False    |         |                                                                                                                                   |                   |
+| headers.add     | object   | false     |        |                 | Append the new headers. The format is `{"name: value",...}`. The values in the header can contain Nginx variables like $remote_addr and $balancer_ip.                                                                                              |
+| headers.set     | object  | false     |        |                 | Overwrite the headers. If header is not exist, will add it. The format is  `{"name": "value", ...}`. The values in the header can contain Nginx variables like $remote_addr and $balancer_ip.                                                                                                |
+| headers.remove  | array   | false     |        |                 | Remove the headers. The format is `["name", ...]`.
 | use_real_request_uri_unsafe | boolean       | False    | false   |                                                                                                                                        | Use real_request_uri (original $request_uri in nginx) to bypass URI normalization. **Enabling this is considered unsafe as it bypasses all URI normalization steps**.                                                                                                                                                                                                                                                                                                     |
 
+## Header Priority
+
+Header Header configurations are executed according to the following priorities:

Review Comment:
   ```suggestion
   Header configurations are executed according to the following priorities:
   ```



##########
t/plugin/proxy-rewrite3.t:
##########
@@ -313,6 +313,57 @@ ngx.var.request_uri: /print_uri_detailed
                 }]]
                 )
 
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 13: rewrite X-Forwarded-Host

Review Comment:
   This test isn't relative to this feature?



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
apisix/core/request.lua:
##########
@@ -39,6 +44,7 @@ local req_get_uri_args = ngx.req.get_uri_args
 local req_set_uri_args = ngx.req.set_uri_args
 
 
+

Review Comment:
   done



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
t/plugin/proxy-rewrite3.t:
##########
@@ -313,6 +313,57 @@ ngx.var.request_uri: /print_uri_detailed
                 }]]
                 )
 
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 13: rewrite X-Forwarded-Host

Review Comment:
   Nope, but this change is to remove duplicate sections from your advice. So I changed some test code.
   
   <img width="575" alt="image" src="https://user-images.githubusercontent.com/11229089/203016510-11a244cd-580b-4871-8906-0f4e0fc1e537.png">
   



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
apisix/plugins/proxy-rewrite.lua:
##########
@@ -150,13 +220,69 @@ do
         core.table.insert(upstream_names, name)
     end
 
-function _M.rewrite(conf, ctx)
-    for _, name in ipairs(upstream_names) do
-        if conf[name] then
-            ctx.var[upstream_vars[name]] = conf[name]
+    local function create_header_operation(hdr_conf)
+        local set = {}
+        local add = {}
+
+        if is_new_headers_conf(hdr_conf) then
+            if hdr_conf.add then
+                for field, value in pairs(hdr_conf.add) do
+                    core.table.insert_tail(add, field, value)
+                end
+            end
+            if hdr_conf.set then
+                for field, value in pairs(hdr_conf.set) do
+                    core.table.insert_tail(set, field, value)
+                end
+            end
+
+        else
+            for field, value in pairs(hdr_conf) do
+                core.table.insert_tail(set, field, value)
+            end
         end
+
+        return {
+            add = add,
+            set = set,
+            remove = hdr_conf.remove or {},
+        }
     end
 
+    local function addHeader(ctx, header_name, header_value)

Review Comment:
   done



-- 
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 #8336: feat: proxy-rewrite support config add set and remove header

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


##########
t/plugin/proxy-rewrite3.t:
##########
@@ -337,3 +337,145 @@ X-Forwarded-Host: apisix.ai
 X-Forwarded-Host: test.com
 --- no_error_log
 [error]
+
+
+
+=== TEST 14: set route header test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "123"},
+                                    "set":{"test2": "2233"},
+                                    "remove":["hello"]
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 15: add exist header in muti-header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+test: bbb
+--- response_headers
+test: sssss, bbb, 123

Review Comment:
   We need to use https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/req.md#add_header. Merging multiple request headers with `,` doesn't obey the standard.



##########
apisix/plugins/proxy-rewrite.lua:
##########
@@ -70,8 +74,58 @@ local schema = {
         },
         headers = {
             description = "new headers for request",
-            type = "object",
-            minProperties = 1,
+            anyOf = {
+                {
+                    type = "object",
+                    minProperties = 1,
+                    patternProperties = {
+                        ["^[^:]+$"] = {
+                            oneOf = {
+                                { type = "string" },
+                                { type = "number" }
+                            }
+                        }
+                    },
+                },
+                {
+                    properties = {
+                        add = {
+                            type = "object",
+                            minProperties = 1,
+                            patternProperties = {
+                                ["^[^:]+$"] = {
+                                    oneOf = {
+                                        { type = "string" },
+                                        { type = "number" }
+                                    }
+                                }
+                            },
+                        },
+                        set = {
+                            type = "object",
+                            minProperties = 1,
+                            patternProperties = {
+                                ["^[^:]+$"] = {
+                                    oneOf = {
+                                        { type = "string" },
+                                        { type = "number" },
+                                    }
+                                }
+                            },
+                        },
+                        remove = {
+                            type = "array",
+                            minItems = 1,
+                            items = {
+                                type = "string",
+                                -- "Set-Cookie"

Review Comment:
   Set-Cookie is a response header. Better to use another example.



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
t/plugin/proxy-rewrite3.t:
##########
@@ -337,3 +337,94 @@ X-Forwarded-Host: apisix.ai
 X-Forwarded-Host: test.com
 --- no_error_log
 [error]
+
+
+
+=== TEST 14: set route add test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "123"},
+                                    "set":{"test2": "2233"},
+                                    "remove":["hello"]
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 15: add exist header in muti-header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+test: bbb
+--- response_headers
+test: sssss, bbb, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 16: add header to exist header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+--- response_headers
+test: sssss, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 17: remove header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+hello: word
+--- response_headers
+hello:
+--- no_error_log
+[error]
+
+
+
+=
+== TEST 18: remove header success
+--- request
+GET /echo HTTP/1.1
+--- response_headers
+test2: 2233
+--- no_error_log
+[error]

Review Comment:
   done



-- 
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 #8336: feat: proxy-rewrite support config add set and remove header

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


##########
apisix/plugins/proxy-rewrite.lua:
##########
@@ -70,8 +74,58 @@ local schema = {
         },
         headers = {
             description = "new headers for request",
-            type = "object",
-            minProperties = 1,
+            anyOf = {

Review Comment:
   `anyOf` means you can configure both the old way and the new way at the same time, which is unnecessary. While `oneOf` means you can configure either the old way or the new way.



##########
t/plugin/proxy-rewrite3.t:
##########
@@ -337,3 +337,145 @@ X-Forwarded-Host: apisix.ai
 X-Forwarded-Host: test.com
 --- no_error_log
 [error]
+
+
+
+=== TEST 14: set route header test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "123"},
+                                    "set":{"test2": "2233"},
+                                    "remove":["hello"]
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 15: add exist header in muti-header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+test: bbb
+--- response_headers
+test: sssss, bbb, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 16: add header to exist header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+--- response_headers
+test: sssss, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 17: remove header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+hello: word
+--- response_headers
+hello:
+--- no_error_log
+[error]
+
+
+
+=== TEST 18: set header success
+--- request
+GET /echo HTTP/1.1
+--- response_headers
+test2: 2233
+--- no_error_log
+[error]
+
+
+
+=== TEST 19: header priority test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "test_in_add"},
+                                    "set":{"test": "test_in_set"}
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 20: set and test priority test
+--- request
+GET /echo HTTP/1.1
+--- response_headers
+test: test_in_set

Review Comment:
   As per the doc you wrote, the `set` operation takes the precedence than `add`, in such a case, the `test` header should have two values.



##########
apisix/plugins/proxy-rewrite.lua:
##########
@@ -163,6 +163,8 @@ local function check_set_headers(headers)
         if #field == 0 then
             return false, 'invalid field length in header'
         end
+
+        core.log.info("header field: ", field)

Review Comment:
   OK, ignore 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] spacewander commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
t/plugin/proxy-rewrite3.t:
##########
@@ -337,3 +337,145 @@ X-Forwarded-Host: apisix.ai
 X-Forwarded-Host: test.com
 --- no_error_log
 [error]
+
+
+
+=== TEST 14: set route header test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "123"},
+                                    "set":{"test2": "2233"},
+                                    "remove":["hello"]
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 15: add exist header in muti-header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+test: bbb
+--- response_headers
+test: sssss, bbb, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 16: add header to exist header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+--- response_headers
+test: sssss, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 17: remove header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+hello: word
+--- response_headers
+hello:
+--- no_error_log
+[error]
+
+
+
+=== TEST 18: set header success
+--- request
+GET /echo HTTP/1.1
+--- response_headers
+test2: 2233
+--- no_error_log
+[error]
+
+
+
+=== TEST 19: header priority test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "test_in_add"},
+                                    "set":{"test": "test_in_set"}
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t

Review Comment:
   Please remove duplicate sections which are set in https://github.com/apache/apisix/blob/ae400b95b91240fb867c3cedc9fa65a6b5593f36/t/plugin/proxy-rewrite3.t#L28



##########
t/plugin/proxy-rewrite3.t:
##########
@@ -337,3 +337,145 @@ X-Forwarded-Host: apisix.ai
 X-Forwarded-Host: test.com
 --- no_error_log
 [error]
+
+
+
+=== TEST 14: set route header test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "123"},
+                                    "set":{"test2": "2233"},
+                                    "remove":["hello"]
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 15: add exist header in muti-header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+test: bbb
+--- response_headers
+test: sssss, bbb, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 16: add header to exist header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+--- response_headers
+test: sssss, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 17: remove header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+hello: word
+--- response_headers
+hello:
+--- no_error_log
+[error]
+
+
+
+=== TEST 18: set header success
+--- request
+GET /echo HTTP/1.1
+--- response_headers
+test2: 2233
+--- no_error_log
+[error]
+
+
+
+=== TEST 19: header priority test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "test_in_add"},
+                                    "set":{"test": "test_in_set"}
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log

Review Comment:
   ditto



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
apisix/plugins/proxy-rewrite.lua:
##########
@@ -163,6 +163,8 @@ local function check_set_headers(headers)
         if #field == 0 then
             return false, 'invalid field length in header'
         end
+
+        core.log.info("header field: ", field)

Review Comment:
   Because the old version has this line, some test cases will check this output.



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
docs/en/latest/plugins/proxy-rewrite.md:
##########
@@ -39,7 +39,10 @@ The `proxy-rewrite` Plugin rewrites Upstream proxy information such as `scheme`,
 | method                      | string        | False    |         | ["GET", "POST", "PUT", "HEAD", "DELETE", "OPTIONS","MKCOL", "COPY", "MOVE", "PROPFIND", "PROPFIND","LOCK", "UNLOCK", "PATCH", "TRACE"] | Rewrites the HTTP method.                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
 | regex_uri                   | array[string] | False    |         |                                                                                                                                        | New upstream forwarding address. Regular expressions can be used to match the URL from client. If it matches, the URL template is forwarded to the Upstream otherwise, the URL from the client is forwarded. When both `uri` and `regex_uri` are configured, `uri` is used first. For example, `[" ^/iresty/(.*)/(.*)/(.*)", "/$1-$2-$3"]`. Here, the first element is the regular expression to match and the second element is the URL template forwarded to the Upstream. |
 | host                        | string        | False    |         |                                                                                                                                        | New Upstream host address.                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
-| headers                     | object        | False    |         |                                                                                                                                        | New Upstream headers. Headers are overwritten if they are already present otherwise, they are added to the present headers. To remove a header, set the header value to an empty string. The values in the header can contain Nginx variables like `$remote_addr` and `$client_addr`.                                                                                                                                                                                        |
+| headers                     | object        | False    |         |                                                                                                                                   |                   |
+| headers.add     | object   | false     |        |                 | Append the new headers. The format is `{"name: value",...}`. The values in the header can contain Nginx variables like $remote_addr and $balancer_ip.                                                                                              |
+| headers.set     | object  | false     |        |                 | Rewriting the headers. The format is  `{"name": "value", ...}`. The values in the header can contain Nginx variables like $remote_addr and $balancer_ip.                                                                                                |

Review Comment:
   done



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
docs/en/latest/plugins/proxy-rewrite.md:
##########
@@ -39,7 +39,10 @@ The `proxy-rewrite` Plugin rewrites Upstream proxy information such as `scheme`,
 | method                      | string        | False    |         | ["GET", "POST", "PUT", "HEAD", "DELETE", "OPTIONS","MKCOL", "COPY", "MOVE", "PROPFIND", "PROPFIND","LOCK", "UNLOCK", "PATCH", "TRACE"] | Rewrites the HTTP method.                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
 | regex_uri                   | array[string] | False    |         |                                                                                                                                        | New upstream forwarding address. Regular expressions can be used to match the URL from client. If it matches, the URL template is forwarded to the Upstream otherwise, the URL from the client is forwarded. When both `uri` and `regex_uri` are configured, `uri` is used first. For example, `[" ^/iresty/(.*)/(.*)/(.*)", "/$1-$2-$3"]`. Here, the first element is the regular expression to match and the second element is the URL template forwarded to the Upstream. |
 | host                        | string        | False    |         |                                                                                                                                        | New Upstream host address.                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
-| headers                     | object        | False    |         |                                                                                                                                        | New Upstream headers. Headers are overwritten if they are already present otherwise, they are added to the present headers. To remove a header, set the header value to an empty string. The values in the header can contain Nginx variables like `$remote_addr` and `$client_addr`.                                                                                                                                                                                        |
+| headers                     | object        | False    |         |                                                                                                                                   |                   |
+| headers.add     | object   | false     |        |                 | Append the new headers. The format is `{"name: value",...}`. The values in the header can contain Nginx variables like $remote_addr and $balancer_ip.                                                                                              |
+| headers.set     | object  | false     |        |                 | Rewriting the headers. The format is  `{"name": "value", ...}`. The values in the header can contain Nginx variables like $remote_addr and $balancer_ip.                                                                                                |

Review Comment:
   yes, look like overwrite is better



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
t/plugin/proxy-rewrite3.t:
##########
@@ -337,3 +337,145 @@ X-Forwarded-Host: apisix.ai
 X-Forwarded-Host: test.com
 --- no_error_log
 [error]
+
+
+
+=== TEST 14: set route header test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "123"},
+                                    "set":{"test2": "2233"},
+                                    "remove":["hello"]
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 15: add exist header in muti-header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+test: bbb
+--- response_headers
+test: sssss, bbb, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 16: add header to exist header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+--- response_headers
+test: sssss, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 17: remove header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+hello: word
+--- response_headers
+hello:
+--- no_error_log
+[error]
+
+
+
+=== TEST 18: set header success
+--- request
+GET /echo HTTP/1.1
+--- response_headers
+test2: 2233
+--- no_error_log
+[error]
+
+
+
+=== TEST 19: header priority test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "test_in_add"},
+                                    "set":{"test": "test_in_set"}
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t

Review Comment:
   done



##########
t/plugin/proxy-rewrite3.t:
##########
@@ -337,3 +337,145 @@ X-Forwarded-Host: apisix.ai
 X-Forwarded-Host: test.com
 --- no_error_log
 [error]
+
+
+
+=== TEST 14: set route header test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "123"},
+                                    "set":{"test2": "2233"},
+                                    "remove":["hello"]
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 15: add exist header in muti-header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+test: bbb
+--- response_headers
+test: sssss, bbb, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 16: add header to exist header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+--- response_headers
+test: sssss, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 17: remove header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+hello: word
+--- response_headers
+hello:
+--- no_error_log
+[error]
+
+
+
+=== TEST 18: set header success
+--- request
+GET /echo HTTP/1.1
+--- response_headers
+test2: 2233
+--- no_error_log
+[error]
+
+
+
+=== TEST 19: header priority test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "test_in_add"},
+                                    "set":{"test": "test_in_set"}
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log

Review Comment:
   done



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
apisix/plugins/proxy-rewrite.lua:
##########
@@ -70,8 +74,58 @@ local schema = {
         },
         headers = {
             description = "new headers for request",
-            type = "object",
-            minProperties = 1,
+            anyOf = {

Review Comment:
   If replace `anyOf` with `oneOf`, the schema can't work correctly.



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
t/plugin/proxy-rewrite3.t:
##########
@@ -337,3 +337,94 @@ X-Forwarded-Host: apisix.ai
 X-Forwarded-Host: test.com
 --- no_error_log
 [error]
+
+
+
+=== TEST 14: set route add test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "123"},
+                                    "set":{"test2": "2233"},
+                                    "remove":["hello"]
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 15: add exist header in muti-header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+test: bbb
+--- response_headers
+test: sssss, bbb, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 16: add header to exist header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+--- response_headers
+test: sssss, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 17: remove header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+hello: word
+--- response_headers
+hello:
+--- no_error_log
+[error]
+
+
+
+=
+== TEST 18: remove header success
+--- request
+GET /echo HTTP/1.1
+--- response_headers
+test2: 2233
+--- no_error_log
+[error]

Review Comment:
   Sorry for the wrong test name, this test case should be named `set header success`. I will fix that and add a new test case for testing the priority.



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
t/plugin/proxy-rewrite3.t:
##########
@@ -337,3 +337,145 @@ X-Forwarded-Host: apisix.ai
 X-Forwarded-Host: test.com
 --- no_error_log
 [error]
+
+
+
+=== TEST 14: set route header test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "123"},
+                                    "set":{"test2": "2233"},
+                                    "remove":["hello"]
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 15: add exist header in muti-header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+test: bbb
+--- response_headers
+test: sssss, bbb, 123

Review Comment:
   This is for test header combination. First combine two existing headers `test: sssss` and `test: bbb`. And then add a new header `test: 123` from proxy_rewrite. Finally, it will combine all headers in one.



-- 
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] tzssangglass commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
docs/en/latest/plugins/proxy-rewrite.md:
##########
@@ -39,7 +39,10 @@ The `proxy-rewrite` Plugin rewrites Upstream proxy information such as `scheme`,
 | method                      | string        | False    |         | ["GET", "POST", "PUT", "HEAD", "DELETE", "OPTIONS","MKCOL", "COPY", "MOVE", "PROPFIND", "PROPFIND","LOCK", "UNLOCK", "PATCH", "TRACE"] | Rewrites the HTTP method.                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
 | regex_uri                   | array[string] | False    |         |                                                                                                                                        | New upstream forwarding address. Regular expressions can be used to match the URL from client. If it matches, the URL template is forwarded to the Upstream otherwise, the URL from the client is forwarded. When both `uri` and `regex_uri` are configured, `uri` is used first. For example, `[" ^/iresty/(.*)/(.*)/(.*)", "/$1-$2-$3"]`. Here, the first element is the regular expression to match and the second element is the URL template forwarded to the Upstream. |
 | host                        | string        | False    |         |                                                                                                                                        | New Upstream host address.                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
-| headers                     | object        | False    |         |                                                                                                                                        | New Upstream headers. Headers are overwritten if they are already present otherwise, they are added to the present headers. To remove a header, set the header value to an empty string. The values in the header can contain Nginx variables like `$remote_addr` and `$client_addr`.                                                                                                                                                                                        |
+| headers                     | object        | False    |         |                                                                                                                                   |                   |
+| headers.add     | object   | false     |        |                 | Append the new headers. The format is `{"name: value",...}`. The values in the header can contain Nginx variables like $remote_addr and $balancer_ip.                                                                                              |
+| headers.set     | object  | false     |        |                 | Rewriting the headers. The format is  `{"name": "value", ...}`. The values in the header can contain Nginx variables like $remote_addr and $balancer_ip.                                                                                                |

Review Comment:
   I think use `headers.rewrite` is more clear. 
   
   What happens if `headers.set` is set, but the actual request does not have a header name that needs to be rewritten?



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
t/plugin/proxy-rewrite3.t:
##########
@@ -337,3 +337,145 @@ X-Forwarded-Host: apisix.ai
 X-Forwarded-Host: test.com
 --- no_error_log
 [error]
+
+
+
+=== TEST 14: set route header test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "123"},
+                                    "set":{"test2": "2233"},
+                                    "remove":["hello"]
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 15: add exist header in muti-header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+test: bbb
+--- response_headers
+test: sssss, bbb, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 16: add header to exist header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+--- response_headers
+test: sssss, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 17: remove header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+hello: word
+--- response_headers
+hello:
+--- no_error_log
+[error]
+
+
+
+=== TEST 18: set header success
+--- request
+GET /echo HTTP/1.1
+--- response_headers
+test2: 2233
+--- no_error_log
+[error]
+
+
+
+=== TEST 19: header priority test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "test_in_add"},
+                                    "set":{"test": "test_in_set"}
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 20: set and test priority test
+--- request
+GET /echo HTTP/1.1
+--- response_headers
+test: test_in_set

Review Comment:
   document updated



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
apisix/plugins/proxy-rewrite.lua:
##########
@@ -70,8 +74,58 @@ local schema = {
         },
         headers = {
             description = "new headers for request",
-            type = "object",
-            minProperties = 1,
+            anyOf = {

Review Comment:
   No, we should use anyOf to maintain downward compatibility. The response-rewrite plugin has the same schema.



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
apisix/plugins/proxy-rewrite.lua:
##########
@@ -150,13 +220,69 @@ do
         core.table.insert(upstream_names, name)
     end
 
-function _M.rewrite(conf, ctx)
-    for _, name in ipairs(upstream_names) do
-        if conf[name] then
-            ctx.var[upstream_vars[name]] = conf[name]
+    local function create_header_operation(hdr_conf)
+        local set = {}
+        local add = {}
+
+        if is_new_headers_conf(hdr_conf) then
+            if hdr_conf.add then
+                for field, value in pairs(hdr_conf.add) do
+                    core.table.insert_tail(add, field, value)
+                end
+            end
+            if hdr_conf.set then
+                for field, value in pairs(hdr_conf.set) do
+                    core.table.insert_tail(set, field, value)
+                end
+            end
+
+        else
+            for field, value in pairs(hdr_conf) do
+                core.table.insert_tail(set, field, value)
+            end
         end
+
+        return {
+            add = add,
+            set = set,
+            remove = hdr_conf.remove or {},
+        }
     end
 
+    local function addHeader(ctx, header_name, header_value)

Review Comment:
   doen



##########
apisix/plugins/proxy-rewrite.lua:
##########
@@ -150,13 +220,69 @@ do
         core.table.insert(upstream_names, name)
     end
 
-function _M.rewrite(conf, ctx)
-    for _, name in ipairs(upstream_names) do
-        if conf[name] then
-            ctx.var[upstream_vars[name]] = conf[name]
+    local function create_header_operation(hdr_conf)
+        local set = {}
+        local add = {}
+
+        if is_new_headers_conf(hdr_conf) then
+            if hdr_conf.add then
+                for field, value in pairs(hdr_conf.add) do
+                    core.table.insert_tail(add, field, value)
+                end
+            end
+            if hdr_conf.set then
+                for field, value in pairs(hdr_conf.set) do
+                    core.table.insert_tail(set, field, value)
+                end
+            end
+
+        else
+            for field, value in pairs(hdr_conf) do
+                core.table.insert_tail(set, field, value)
+            end
         end
+
+        return {
+            add = add,
+            set = set,
+            remove = hdr_conf.remove or {},
+        }
     end
 
+    local function addHeader(ctx, header_name, header_value)
+        local oldHeader = core.request.header(ctx, header_name)

Review Comment:
   done



-- 
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] tzssangglass commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
t/plugin/proxy-rewrite3.t:
##########
@@ -337,3 +337,145 @@ X-Forwarded-Host: apisix.ai
 X-Forwarded-Host: test.com
 --- no_error_log
 [error]
+
+
+
+=== TEST 14: set route header test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "123"},
+                                    "set":{"test2": "2233"},
+                                    "remove":["hello"]
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 15: add exist header in muti-header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+test: bbb
+--- response_headers
+test: sssss, bbb, 123

Review Comment:
   Is it necessary to merge header with the same name? I'm not sure. cc @spacewander 



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
t/plugin/proxy-rewrite3.t:
##########
@@ -337,3 +337,145 @@ X-Forwarded-Host: apisix.ai
 X-Forwarded-Host: test.com
 --- no_error_log
 [error]
+
+
+
+=== TEST 14: set route header test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "123"},
+                                    "set":{"test2": "2233"},
+                                    "remove":["hello"]
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 15: add exist header in muti-header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+test: bbb
+--- response_headers
+test: sssss, bbb, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 16: add header to exist header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+test: sssss
+--- response_headers
+test: sssss, 123
+--- no_error_log
+[error]
+
+
+
+=== TEST 17: remove header
+--- request
+GET /echo HTTP/1.1
+--- more_headers
+hello: word
+--- response_headers
+hello:
+--- no_error_log
+[error]
+
+
+
+=== TEST 18: set header success
+--- request
+GET /echo HTTP/1.1
+--- response_headers
+test2: 2233
+--- no_error_log
+[error]
+
+
+
+=== TEST 19: header priority test
+--- 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,
+                 [[{
+                        "methods": ["GET"],
+                        "plugins": {
+                            "proxy-rewrite": {
+                                "headers": {
+                                    "add":{"test": "test_in_add"},
+                                    "set":{"test": "test_in_set"}
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/echo"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 20: set and test priority test
+--- request
+GET /echo HTTP/1.1
+--- response_headers
+test: test_in_set

Review Comment:
   And change `anyOf ` to `oneOf` is done



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
t/plugin/proxy-rewrite3.t:
##########
@@ -313,6 +313,57 @@ ngx.var.request_uri: /print_uri_detailed
                 }]]
                 )
 
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 13: rewrite X-Forwarded-Host

Review Comment:
   Nope, but this change is to remove duplicate sections from your advice.
   
   <img width="575" alt="image" src="https://user-images.githubusercontent.com/11229089/203016510-11a244cd-580b-4871-8906-0f4e0fc1e537.png">
   



-- 
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] mscb402 commented on a diff in pull request #8336: feat: proxy-rewrite support config add set and remove header

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


##########
apisix/plugins/proxy-rewrite.lua:
##########
@@ -70,8 +74,58 @@ local schema = {
         },
         headers = {
             description = "new headers for request",
-            type = "object",
-            minProperties = 1,
+            anyOf = {

Review Comment:
   If replace `anyOf` with `oneOf`, the schema can't work correctly.



##########
apisix/plugins/proxy-rewrite.lua:
##########
@@ -70,8 +74,58 @@ local schema = {
         },
         headers = {
             description = "new headers for request",
-            type = "object",
-            minProperties = 1,
+            anyOf = {

Review Comment:
   Done



-- 
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 #8336: feat: proxy-rewrite support config add set and remove header

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


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