Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: proxy-rewrite host support host with port #3428

Merged
merged 1 commit into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
76 changes: 76 additions & 0 deletions t/plugin/proxy-rewrite.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]