diff --git a/apisix/plugins/proxy-rewrite.lua b/apisix/plugins/proxy-rewrite.lua index c7c37114990f..c678b5957ee6 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 a7430109e686..58f0ffdcb6f8 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]