apisix icon indicating copy to clipboard operation
apisix copied to clipboard

bug: if route has a proxy-rewrite plugin , proxy-rewrite plugin in service does not take effect

Open cverdela opened this issue 5 years ago • 6 comments

Issue description

Environment

  • apisix version (cmd: apisix version):2.3 (docker image apache/apisix:2.3-alpine )
  • OS (cmd: uname -a):Linux 570c5064c3f9 4.9.93-linuxkit-aufs #1 SMP Wed Jun 6 16:55:56 UTC 2018 x86_64 Linux ( docker )
  • OpenResty / Nginx version (cmd: nginx -V or openresty -V): openresty/1.19.3.1
  • etcd version, if have (cmd: run curl http://127.0.0.1:9090/v1/server_info to get the info from server-info API):3.4.9
  • apisix-dashboard version, if have:2.4
  • luarocks version, if the issue is about installation (cmd: luarocks --version):luarocks 3.3.1

Minimal test code / Steps to reproduce the issue

any upstream any route

service config : { "update_time": 1618987372, "id": "348075546078347976", "upstream_id": "351385449672999625", "plugins": { "proxy-rewrite": { "headers": { "1": "2" } }, "serverless-pre-function": { "phase": "log", "functions" : ["return function() local headers_tab = ngx.req.get_headers() for k,v in pairs(headers_tab) do ngx.log(ngx.ERR,'--header--'..k..':'..v..'--header--') end end"] } }, "desc": "测试", "name": "test", "create_time": 1616998792 }

What's the actual result? (including assertion message & call stack if applicable)

headers without "1":"2"

What's the expected result?

headers with "1":"2"

cverdela avatar Apr 22 '21 01:04 cverdela

Can't reproduce at my side. I got:

2021/04/22 10:08:09 [error] 2454#2454: *2 [lua] [string "return function() local headers_tab = ngx.req..."]:1: func(): --header--1:2--header-- while logging request, client: 127.0.0.1, server: localhost, request: "GET /hello HTTP/1.1", upstream: "http://127.0.0.1:1980/hello", host: "localhost"
2021/04/22 10:08:09 [error] 2454#2454: *2 [lua] [string "return function() local headers_tab = ngx.req..."]:1: func(): --header--host:localhost--header-- while logging request, client: 127.0.0.1, server: localhost, request: "GET /hello HTTP/1.1", upstream: "http://127.0.0.1:1980/hello", host: "localhost"
2021/04/22 10:08:09 [error] 2454#2454: *2 [lua] [string "return function() local headers_tab = ngx.req..."]:1: func(): --header--connection:close--header-- while logging request, client: 127.0.0.1, server: localhost, request: "GET /hello HTTP/1.1", upstream: "http://127.0.0.1:1980/hello", host: "localhost"

Here is my route configuration:

{
    "uri": "/hello",
    "service_id": 1
}

spacewander avatar Apr 22 '21 02:04 spacewander

Issue description Environment apisix version (cmd: apisix version):2.3 (docker image apache/apisix:2.3-alpine ) OS (cmd: uname -a):Linux 570c5064c3f9 4.9.93-linuxkit-aufs #1 SMP Wed Jun 6 16:55:56 UTC 2018 x86_64 Linux ( docker ) OpenResty / Nginx version (cmd: nginx -V or openresty -V): openresty/1.19.3.1 etcd version, if have (cmd: run curl http://127.0.0.1:9090/v1/server_info to get the info from server-info API):3.4.9 apisix-dashboard version, if have:2.4 luarocks version, if the issue is about installation (cmd: luarocks --version):luarocks 3.3.1 Minimal test code / Steps to reproduce the issue

any upstream

route conifg :

{ "status": 1, "name": "web2", "uris": [ "/we/" ], "methods": [ "GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS", "PATCH" ], "id": "351385589259436746", "create_time": 1618971732, "plugins": { "proxy-rewrite": { "scheme": "http", "regex_uri": ["^/we/web(.)", "/web$1"] } }, "update_time": 1618971986, "labels": { "API_VERSION": "1" }, "service_id": "348075546078347976" }

service config : { "update_time": 1618987372, "id": "348075546078347976", "upstream_id": "351385449672999625", "plugins": { "proxy-rewrite": { "headers": { "1": "2" } }, "serverless-pre-function": { "phase": "log", "functions" : ["return function() local headers_tab = ngx.req.get_headers() for k,v in pairs(headers_tab) do ngx.log(ngx.ERR,'--header--'..k..':'..v..'--header--') end end"] } }, "desc": "测试", "name": "test", "create_time": 1616998792 }

What's the actual result? (including assertion message & call stack if applicable) headers without "1":"2"

What's the expected result? headers with "1":"2"

cverdela avatar Apr 22 '21 03:04 cverdela

update

cverdela avatar Apr 22 '21 03:04 cverdela

@spacewander

cverdela avatar Apr 22 '21 03:04 cverdela

When both Route and Service enable the same plugin, the Route parameter has a higher priority than Service.

However,I want to add proxy-rewrite plugin to both route and service

cverdela avatar Apr 22 '21 03:04 cverdela

APISIX doesn't support running the same plugin twice. This breaks many assumptions and requires rewriting much of the code.

spacewander avatar Apr 22 '21 03:04 spacewander