MarsOu1995 opened a new issue #1647:
URL: https://github.com/apache/incubator-shenyu/issues/1647
## Describe the bug
Repeated judgment conditions cause ‘addprefix’ to fail to work as expected.
## Environment
- Shenyu version(s): [e.g. ALL and 2.4.0-SNAPSHOT]
## Steps to reproduce
#### [example 1]
- content-path-plugin seletor["/order/**"] handle params :
{"contextPath":"/order","addPrefix":"/order/v1"}.
- send a request (example):http://localhost:9195/order/findById
#### [example 2] This may be rare in reality.
- content-path-plugin seletor["/order/**"] handle params :
{"contextPath":"","addPrefix":"/v1"}.
- send a request (example):http://localhost:9195/order/findById
## Expected behavior
- [example 1] I think this will be forwarded to real uri is :
/order/v1/findById
- [example 2] I think this will be forwarded to real uri is :
/v1/order/findById
## Debug logs
-[example 1] content-path-plugin will forward the request to /findById (Not
expected )
-[example 2] content-path-plugin will forward the request to /order/findById
(Not expected )
<details>
<summary>Click to expand [example 1]</summary>
```
2021-06-19 14:52:34 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.base.AbstractShenyuPlugin - context_path selector
success match , selector name :/context-path/order
2021-06-19 14:52:34 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.base.AbstractShenyuPlugin - context_path rule success
match , rule name :/context-path/order
2021-06-19 14:52:34 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.base.AbstractShenyuPlugin - divide selector success
match , selector name :/order
2021-06-19 14:52:34 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.base.AbstractShenyuPlugin - divide rule success match
, rule name :/order
2021-06-19 14:52:34 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.httpclient.WebClientPlugin - The request urlPath is
http://localhost:8000/findById, retryTimes is 1
```
</details>
<details>
<summary>Click to expand [example 2]</summary>
```
2021-06-19 15:11:38 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.base.AbstractShenyuPlugin - context_path selector
success match , selector name :/context-path/order
2021-06-19 15:11:38 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.base.AbstractShenyuPlugin - context_path rule success
match , rule name :/context-path/order
2021-06-19 15:11:38 [shenyu-netty-nio-2] ERROR
org.apache.shenyu.plugin.context.path.ContextPathPlugin - context path rule
configuration is null :RuleData(id=1406142451711590400,
name=/context-path/order, pluginName=context_path,
selectorId=1406142308035706880, matchMode=0, sort=1, enabled=true, loged=true,
handle={"addPrefix":"/order/v1","contextPath":""},
conditionDataList=[ConditionData(paramType=uri, operator=match, paramName=/,
paramValue=/order/**)])
2021-06-19 15:11:38 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.base.AbstractShenyuPlugin - divide selector success
match , selector name :/order
2021-06-19 15:11:38 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.base.AbstractShenyuPlugin - divide rule success match
, rule name :/order
2021-06-19 15:11:38 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.httpclient.WebClientPlugin - The request urlPath is
http://localhost:8000/order/findById, retryTimes is 1
```
</details>
## Fix
- So i made some modifications.
<details>
<summary>Click to expand [example 1]</summary>
```
2021-06-19 15:03:36 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.base.AbstractShenyuPlugin - context_path selector
success match , selector name :/context-path/order
2021-06-19 15:03:36 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.base.AbstractShenyuPlugin - context_path rule success
match , rule name :/context-path/order
2021-06-19 15:03:36 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.base.AbstractShenyuPlugin - divide selector success
match , selector name :/order
2021-06-19 15:03:36 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.base.AbstractShenyuPlugin - divide rule success match
, rule name :/order
2021-06-19 15:03:36 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.httpclient.WebClientPlugin - The request urlPath is
http://localhost:8000/order/v1/findById, retryTimes is 1
```
</details>
<details>
<summary>Click to expand [example 2]</summary>
```
2021-06-19 15:18:39 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.base.AbstractShenyuPlugin - context_path selector
success match , selector name :/context-path/order
2021-06-19 15:18:39 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.base.AbstractShenyuPlugin - context_path rule success
match , rule name :/context-path/order
2021-06-19 15:18:39 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.base.AbstractShenyuPlugin - divide selector success
match , selector name :/order
2021-06-19 15:18:39 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.base.AbstractShenyuPlugin - divide rule success match
, rule name :/order
2021-06-19 15:18:39 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.httpclient.WebClientPlugin - The request urlPath is
http://localhost:8000/v1/order/findById, retryTimes is 1
```
</details>
- and content-path-plugin seletor["/order/**"] handle params :
{"contextPath":"/order","addPrefix":"/v1"}.
<details>
<summary>Click to expand</summary>
```
2021-06-19 15:20:30 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.base.AbstractShenyuPlugin - context_path selector
success match , selector name :/context-path/order
2021-06-19 15:20:30 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.base.AbstractShenyuPlugin - context_path rule success
match , rule name :/context-path/order
2021-06-19 15:20:30 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.base.AbstractShenyuPlugin - divide selector success
match , selector name :/order
2021-06-19 15:20:30 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.base.AbstractShenyuPlugin - divide rule success match
, rule name :/order
2021-06-19 15:20:30 [shenyu-netty-nio-2] INFO
org.apache.shenyu.plugin.httpclient.WebClientPlugin - The request urlPath is
http://localhost:8000/v1/findById, retryTimes is 1
```
</details>
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]