Baoyuantop commented on code in PR #13283:
URL: https://github.com/apache/apisix/pull/13283#discussion_r3128832201
##########
docs/en/latest/plugins/proxy-rewrite.md:
##########
@@ -42,7 +42,7 @@ The `proxy-rewrite` Plugin offers options to rewrite requests
that APISIX forwar
|-----------------------------|---------------|----------|---------|----------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| uri | string | False | |
| New Upstream URI path. 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"] | HTTP method to rewrite
requests to use.
|
-| regex_uri | array[string] | False | |
| Regular expressions used to
match the URI path from client requests and compose a new Upstream URI path.
When both `uri` and `regex_uri` are configured, `uri` has a higher priority.
The array should contain one or more **key-value pairs**, with the key being
the regular expression to match URI against and value being the new Upstream
URI path. For example, with `["^/iresty/(. *)/(. *)", "/$1-$2", ^/theothers/*",
"/theothers"]`, if a request is originally sent to `/iresty/hello/world`, the
Plugin will rewrite the Upstream URI path to `/iresty/hello-world`; if a
request is originally sent to `/theothers/hello/world`, the Plugin will rewrite
the Upstream URI path to `/theothers`. |
+| regex_uri | array[string] | False | |
| Regular expressions used to
match the URI path from client requests and compose a new Upstream URI path.
When both `uri` and `regex_uri` are configured, `uri` has a higher priority.
The array should contain one or more **key-value pairs**, with the key being
the regular expression to match URI against and value being the new Upstream
URI path. For example, with `["^/iresty/(.*)/(.*)", "/$1-$2", "^/theothers/*",
"/theothers"]`, if a request is originally sent to `/iresty/hello/world`, the
Plugin will rewrite the Upstream URI path to `/hello-world`; if a request is
originally sent to `/theothers/hello/world`, the Plugin will rewrite the
Upstream URI path to `/theothers`. |
Review Comment:
The key evidence is in `apisix/plugins/proxy-rewrite.lua:294-308`: after
`regex_uri` matches, APISIX runs `re_sub(upstream_uri, pattern, replacement,
"jo")` on the whole upstream URI. That means only the matched part is replaced,
while any unmatched suffix is preserved. The existing test
`t/plugin/proxy-rewrite.t:572-602` shows this behavior as well: when the
pattern `^/test/(.*)/(.*)/(.*)` covers the full path,
`/test/plugin/proxy/rewrite` becomes exactly `/plugin_proxy_rewrite`.
In this PR, the docs still use `"^/theothers/*" -> "/theothers"` and say
`/theothers/hello/world` will be rewritten to `/theothers`. That pattern does
not consume the trailing `hello/world` segment, so it cannot produce the
documented result. In other words, this revision fixes the first wrong example,
but the second wrong example still remains in both the English and Chinese docs.
Please update the second example to a pattern that consumes the remaining
path as well (for example, if the intent is to collapse any `/theothers/...`
request to `/theothers`, something like `^/theothers(/.*)?$` would be closer to
the actual behavior), and then I can take another quick look.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]