Skip to content

Commit

Permalink
proxy-rewrite host support port
Browse files Browse the repository at this point in the history
  • Loading branch information
halfcrazy committed Jan 26, 2021
1 parent 3db8ebe commit 4b49202
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apisix/plugins/proxy-rewrite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
75 changes: 75 additions & 0 deletions t/plugin/proxy-rewrite.t
Original file line number Diff line number Diff line change
Expand Up @@ -1297,3 +1297,78 @@ 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:1983": 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 HTTP/1.1
--- response_body
uri: /plugin_proxy_rewrite
host: test.com:6443
--- no_error_log
[error]

0 comments on commit 4b49202

Please sign in to comment.