apisix icon indicating copy to clipboard operation
apisix copied to clipboard

bugfix: when both route and global rules setted proxy-rewrite plugin,…

Open panhow opened this issue 2 years ago • 7 comments

when proxy-rewrite plugin is both set in route and global rule, uri rewrite won't work, cause ctx.var.upstream_uri will only sync once to ngx.var.upstream_uri

Description

Fixes # (issue) How to reproduce it?

# create a global_rules
curl 127.0.0.1:8081/apisix/admin/global_rules/proxy_set_header -H 'x-api-key: xxx' -XPUT \
	-d '{"plugins":{"proxy-rewrite":{"headers":{"bb": "cc"}}}}'

# create a route for debug
curl 127.0.0.1:8081/apisix/admin/routes/proxy-rewrite-test -H 'x-api-key: xxx'  -XPUT -d '{
	"uri": "/server/*",
	"host": "apisix.debug",
	"plugins": {
		"proxy-rewrite":{
			"regex_uri": [
			    "/server/(.*)",
                             "/$1"
			]
		}
	},
	"upstream": {
		"type": "roundrobin",
		"nodes": {
			"127.0.0.1:7777": 1
		}
	}
}'

# run an http server
python -m SimpleHTTPServer 7777 &

# send a requests
curl 127.0.0.1/server/123123 -H 'host: apisix.debug'
# expect access log
/123123

# actual log
/server/123123
# remove global rules, everything works fine
curl 127.0.0.1:8081/apisix/admin/global_rules/proxy_set_header -H 'x-api-key: xxx' -DELETE
curl 127.0.0.1/server/123123 -H 'host: apisix.debug'

Checklist

  • [ ] I have explained the need for this PR and the problem it solves
  • [ ] I have explained the changes or the new features added to this PR
  • [ ] I have added tests corresponding to this change
  • [ ] I have updated the documentation to reflect this change
  • [ ] I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

panhow avatar Jun 23 '22 12:06 panhow

nice!

Jary-mf avatar Jun 23 '22 12:06 Jary-mf

@tokers @spacewander ping

withlin avatar Jun 23 '22 12:06 withlin

@panhow We need some test cast cases to verify the changes are effective.

tokers avatar Jun 23 '22 13:06 tokers

BTW,although there is no uri or regex_uri configuration in global_rules, the code logic still affects upstream_uri, which seems a bit unreasonable :)

Jary-mf avatar Jun 24 '22 06:06 Jary-mf

BTW,although there is no uri or regex_uri configuration in global_rules, the code logic still affects upstream_uri, which seems a bit unreasonable :)

We submit another PR to solve it.

spacewander avatar Jun 24 '22 07:06 spacewander

@panhow We need some test cast cases to verify the changes are effective.

@panhow You can add the test in https://github.com/apache/apisix/blob/master/t/plugin/proxy-rewrite3.t. You can refer to https://github.com/apache/apisix/blob/master/docs/en/latest/internal/testing-framework.md to write and run the test locally.

spacewander avatar Jun 24 '22 07:06 spacewander

This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If you think that's incorrect or this pull request should instead be reviewed, please simply write any comment. Even if closed, you can still revive the PR at any time or discuss it on the [email protected] list. Thank you for your contributions.

github-actions[bot] avatar Aug 30 '22 10:08 github-actions[bot]

This pull request/issue has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.

github-actions[bot] avatar Sep 27 '22 10:09 github-actions[bot]