You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by mo...@apache.org on 2023/04/20 07:03:37 UTC
[apisix] branch master updated: fix: proxy-rewrite should set ngx.var.uri (#9309)
This is an automated email from the ASF dual-hosted git repository.
monkeydluffy 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 54159168e fix: proxy-rewrite should set ngx.var.uri (#9309)
54159168e is described below
commit 54159168ee52f9d8614b6706842ddc5e5af2c4fb
Author: jinhua luo <ho...@163.com>
AuthorDate: Thu Apr 20 15:03:30 2023 +0800
fix: proxy-rewrite should set ngx.var.uri (#9309)
---
apisix/plugins/proxy-rewrite.lua | 3 +++
t/plugin/proxy-rewrite.t | 8 +++++++-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/apisix/plugins/proxy-rewrite.lua b/apisix/plugins/proxy-rewrite.lua
index 8b1df5aaa..c0c52413a 100644
--- a/apisix/plugins/proxy-rewrite.lua
+++ b/apisix/plugins/proxy-rewrite.lua
@@ -22,6 +22,7 @@ local ngx = ngx
local type = type
local re_sub = ngx.re.sub
local re_match = ngx.re.match
+local req_set_uri = ngx.req.set_uri
local sub_str = string.sub
local str_find = core.string.find
@@ -317,6 +318,8 @@ function _M.rewrite(conf, ctx)
upstream_uri = core.utils.uri_safe_encode(upstream_uri)
end
+ req_set_uri(upstream_uri)
+
if ctx.var.is_args == "?" then
if index then
ctx.var.upstream_uri = upstream_uri .. "&" .. (ctx.var.args or "")
diff --git a/t/plugin/proxy-rewrite.t b/t/plugin/proxy-rewrite.t
index 558fd9ade..4d7465862 100644
--- a/t/plugin/proxy-rewrite.t
+++ b/t/plugin/proxy-rewrite.t
@@ -1180,7 +1180,7 @@ done
-=== TEST 43: set route(rewrite host with port)
+=== TEST 43: set route(rewrite host with port), ensure ngx.var.uri matched the rewritten version
--- config
location /t {
content_by_lua_block {
@@ -1193,6 +1193,12 @@ done
"proxy-rewrite": {
"uri": "/uri",
"host": "test.com:6443"
+ },
+ "serverless-post-function": {
+ "phase": "access",
+ "functions" : ["return function(conf, ctx)
+ assert(ngx.var.uri == \"/uri\", \"proxy-rewrite do not call ngx.req.set_uri\")
+ end"]
}
},
"upstream": {