-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 support miltiple regex pattern matching #9194
feat: proxy_rewrite support miltiple regex pattern matching #9194
Conversation
61850a1
to
fbe5af4
Compare
Hi @fengxsong, Test cases are needed! |
done |
ping @monkeyDluffy6017 |
I will check this later, THX @fengxsong |
Is the ci failure caused by this code change? https://github.com/apache/apisix/actions/runs/4685205482/jobs/8302219899?pr=9194 |
@fengxsong please add doc to describe this feature. |
@@ -38,7 +38,8 @@ The `proxy-rewrite` Plugin rewrites Upstream proxy information such as `scheme`, | |||
|-----------------------------|---------------|----------|---------|----------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | |||
| uri | string | False | | | New Upstream forwarding address. Value supports [Nginx variables](https://nginx.org/en/docs/http/ngx_http_core_module.html). For example, `$arg_name`. | | |||
| method | string | False | | ["GET", "POST", "PUT", "HEAD", "DELETE", "OPTIONS","MKCOL", "COPY", "MOVE", "PROPFIND", "PROPFIND","LOCK", "UNLOCK", "PATCH", "TRACE"] | Rewrites the HTTP method. | | |||
| regex_uri | array[string] | False | | | New upstream forwarding address. Regular expressions can be used to match the URL from client. If it matches, the URL template is forwarded to the Upstream otherwise, the URL from the client is forwarded. When both `uri` and `regex_uri` are configured, `uri` is used first. For example, `[" ^/iresty/(.*)/(.*)/(.*)", "/$1-$2-$3"]`. Here, the first element is the regular expression to match and the second element is the URL template forwarded to the Upstream. | | |||
| none_match_abort | boolean | False | `false` | | Abort with 404 status code when none of regex_uri matched, useful when making only those routes that match regular expression patterns public. | | |||
| regex_uri | array[string] | False | | | New upstream forwarding address. Regular expressions can be used to match the URL from client. If it matches, the URL template is forwarded to the Upstream otherwise, the URL from the client is forwarded if `none_match_abort=false`. When both `uri` and `regex_uri` are configured, `uri` is used first. For example, `["^/iresty/(.*)/(.*)/(.*)", "/$1-$2-$3", ^/theothers/(.*)/(.*)", "/theothers/$1-$2"]`. Here, the first and the third elements are the regular expressions to match, the second and the fourth elements are the URL templates forwarded to the Upstream. Length of this property must be a even number. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to declare it supports multiple patterns for matching and substitution. It will iterate all patterns one by one until a successful match and substitution.
b930aba
to
2e9dff3
Compare
GET /test/plugin/proxy/rewrite/hello HTTP/1.1 | ||
--- http_config | ||
server { | ||
listen 8125; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are many URIs for testing in lib.server, usually, it is not necessary to start the server separately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think he's following the other test cases in this test case file
apisix/plugins/proxy-rewrite.lua
Outdated
|
||
upstream_uri = uri | ||
if ctx.proxy_rewrite_regex_uri_captures == nil and conf.none_match_abort then | ||
return 404, { error_msg = "404 Route Not Found" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message is wrong, but the rewrite was not successful, not that the route did not match successfully
I don't understand why the none_match_abort parameter should be added, the proxy-rewrite plugin should not be able to block the request |
There are some scenarios we don't want to expose all of our APIs, for example.
we can only expose From the point of view of ability classification, |
2e9dff3
to
1bca225
Compare
ea52a3a
to
3b30e60
Compare
3b30e60
to
610c7b6
Compare
@fengxsong please fix the ci |
610c7b6
to
ac575b6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rebase to the latest master, because proxy-rewrite.lua has merged new changes.
Signed-off-by: fengxsong <fengxsong@outlook.com>
Signed-off-by: fengxsong <fengxsong@outlook.com>
Signed-off-by: fengxsong <fengxsong@outlook.com>
ac575b6
to
4977cd0
Compare
* upstream/master: (42 commits) fix: add `rust-check` target to the makefile for deps pre-checking (apache#9453) test: remove duplicate `proto` unit test file and tweak test case title (apache#9445) feat: proxy-mirror add grpc and grpcs support (apache#9388) test: replace all httpbin upstream (apache#9452) fix: 404 error in ci test (apache#9447) fix: body-transformer plugin return raw body anytime (apache#9446) fix(ci): fips: ensure apisix compiles with openssl3 (apache#9427) chore(deps): bump actions/stale from 7 to 8 (apache#9159) chore(deps): bump actions/setup-node from 3.5.1 to 3.6.0 (apache#8625) chore(test): split the access log of apisix and test server (apache#8819) docs: fix grammar (apache#9395) fix(wolf-rbac): other plugin in consumer not effective when consumer used wolf-rbac plugin (apache#9287) (apache#9298) docs: use shell instead of Python to configure protos resources (apache#9414) docs: add guide to authenticate websocket connections (apache#9369) docs: updated Stream Proxy doc (apache#9367) feat: proxy_rewrite support miltiple regex pattern matching (apache#9194) feat: route-level MTLS (apache#9322) ci: tcp logger with real logger server (apache#9392) fix: always parse domain when host is domain name (apache#9332) docs: CHANGELOG.md Chinese docs lint (apache#9411) ...
Description
As explained in #9179, this PR is a preliminary implementation. The following changes are included:
a new property that named;none_match_abort
, whennone_match_abort=true
and none of regex_uri matched, apisix will return 404 directly, for compatibility it defaults tofalse
regex_uri
, but it must have a even length;With this feature, we can now configure
regex_uri
likeChecklist