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 9a1831d  fix(proxy-rewrite): make sure proxy-rewrite update the 
core.request.header cache (#5914)
9a1831d is described below

commit 9a1831d656b527fcb07ce5e556da0ccc502300bc
Author: leslie <[email protected]>
AuthorDate: Fri Dec 24 16:02:38 2021 +0800

    fix(proxy-rewrite): make sure proxy-rewrite update the core.request.header 
cache (#5914)
---
 apisix/plugins/proxy-rewrite.lua |  4 ++--
 t/plugin/proxy-rewrite2.t        | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/apisix/plugins/proxy-rewrite.lua b/apisix/plugins/proxy-rewrite.lua
index 0780b21..eff3c2a 100644
--- a/apisix/plugins/proxy-rewrite.lua
+++ b/apisix/plugins/proxy-rewrite.lua
@@ -209,8 +209,8 @@ function _M.rewrite(conf, ctx)
 
     local field_cnt = #conf.headers_arr
     for i = 1, field_cnt, 2 do
-        ngx.req.set_header(conf.headers_arr[i],
-                           core.utils.resolve_var(conf.headers_arr[i+1], 
ctx.var))
+        core.request.set_header(ctx, conf.headers_arr[i],
+                                core.utils.resolve_var(conf.headers_arr[i+1], 
ctx.var))
     end
 
     if conf.method then
diff --git a/t/plugin/proxy-rewrite2.t b/t/plugin/proxy-rewrite2.t
index e3d1b7b..4fbfe55 100644
--- a/t/plugin/proxy-rewrite2.t
+++ b/t/plugin/proxy-rewrite2.t
@@ -175,3 +175,36 @@ GET /echo
 X-Forwarded-Proto: grpc
 --- response_headers
 X-Forwarded-Proto: https
+
+
+
+=== TEST 6: make sure X-Forwarded-Proto hit the `core.request.header` cache
+--- apisix_yaml
+routes:
+  -
+    id: 1
+    uri: /echo
+    plugins:
+        serverless-pre-function:
+            phase: rewrite
+            functions:
+              - return function(conf, ctx) local core = 
require("apisix.core"); ngx.log(ngx.ERR, core.request.header(ctx, "host")); end
+        proxy-rewrite:
+            headers:
+                X-Forwarded-Proto: https-rewrite
+    upstream_id: 1
+upstreams:
+  -
+    id: 1
+    nodes:
+        "127.0.0.1:1980": 1
+    type: roundrobin
+#END
+--- request
+GET /echo
+--- more_headers
+X-Forwarded-Proto: grpc
+--- response_headers
+X-Forwarded-Proto: https-rewrite
+--- error_log
+localhost

Reply via email to