This is an automated email from the ASF dual-hosted git repository. spacewander pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push: new 2b532f0 feat: proxy-rewrite host support host with port (#3428) 2b532f0 is described below commit 2b532f06ba8a48da0b8c21147bee7d2cb0391a2e Author: halfcrazy <hackzhu...@gmail.com> AuthorDate: Wed Jan 27 10:22:10 2021 +0800 feat: proxy-rewrite host support host with port (#3428) Fix #3136 --- apisix/plugins/proxy-rewrite.lua | 2 +- t/plugin/proxy-rewrite.t | 76 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/apisix/plugins/proxy-rewrite.lua b/apisix/plugins/proxy-rewrite.lua index c7c3711..c678b59 100644 --- a/apisix/plugins/proxy-rewrite.lua +++ b/apisix/plugins/proxy-rewrite.lua @@ -48,7 +48,7 @@ local schema = { host = { description = "new host for upstream", type = "string", - pattern = "^[0-9a-zA-Z-.]+$", + pattern = [[^[0-9a-zA-Z-.]+(:\d{1,5})?$]], }, scheme = { description = "new scheme for upstream", diff --git a/t/plugin/proxy-rewrite.t b/t/plugin/proxy-rewrite.t index a743010..58f0ffd 100644 --- a/t/plugin/proxy-rewrite.t +++ b/t/plugin/proxy-rewrite.t @@ -1297,3 +1297,79 @@ GET /test?new_uri=hello hello world --- no_error_log [error] + + + +=== TEST 44: host with port +--- config + location /t { + content_by_lua_block { + local plugin = require("apisix.plugins.proxy-rewrite") + local ok, err = plugin.check_schema({ + host = 'apisix.iresty.com:6443', + }) + if not ok then + ngx.say(err) + end + + ngx.say("done") + } + } +--- request +GET /t +--- response_body +done +--- no_error_log +[error] + + + +=== TEST 45: set route(rewrite host with port) +--- 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": { + "uri": "/uri", + "host": "test.com:6443" + } + }, + "upstream": { + "nodes": { + "127.0.0.1:1980": 1 + }, + "type": "roundrobin" + }, + "uri": "/hello" + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed +--- no_error_log +[error] + + + +=== TEST 46: rewrite host with port +--- request +GET /hello +--- response_body +uri: /uri +host: test.com:6443 +x-real-ip: 127.0.0.1 +--- no_error_log +[error]