You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by GitBox <gi...@apache.org> on 2021/10/09 01:09:43 UTC

[GitHub] [incubator-shenyu] longhujing commented on issue #2200: [BUG] DividePlugin插件, 如果Url中包含特殊字符如#等会导致请求错误

longhujing commented on issue #2200:
URL: https://github.com/apache/incubator-shenyu/issues/2200#issuecomment-939197335


   抱歉,昨天我提出的解决方案其实存在一些问题,我在进行debug的时候,发现问题的根本原因是这样的
   
   在WebClientPlugin里面构造出来的URL是这样的
   http://172.20.218.131:8080/test?name=#&page=1&pageSize=1
   事实上我们期望的是这样的
   http://172.20.218.131:8080/test?name=%23&page=1&pageSize=1,也就是构造出来的URL需要对特殊字符进行转义处理,但是这里并没有,就会导致应用解析错误
   
   ![image](https://user-images.githubusercontent.com/54448899/136638072-57be40db-88b5-43e0-8211-99fabff73527.png)
   
   然后我昨天提的,将getQuery()改成getRawQuery(),这样拿到的query参数就是已经转义过的,但是在构造新的URL的时候出现了意料之外的结果
   ![image](https://user-images.githubusercontent.com/54448899/136638288-52b62ab1-fa44-4864-a224-4623f2989158.png)
   这里又对%进行了一次转义,转成了%25,于是
   本来期望的是这样的:http://172.20.218.131:8080/test?name=%23&page=1&pageSize=1
   结果给我变成了这样:http://172.20.218.131:8080/test?name=%2523&page=1&pageSize=1
   
   所以这里应该重写uri的构造方法,也就是替换掉这一段
   WebClient.RequestBodySpec requestBodySpec = webClient.method(method).uri(urlPath);
   
   使用自定义的uri构造方式,像这样
           WebClient.RequestBodySpec requestBodySpec = webClient
                   .method(method)
                   .uri(urlPath, uriBuilder -> uriBuilder.replaceQueryParams(exchange.getRequest().getQueryParams()).build());
   ![image](https://user-images.githubusercontent.com/54448899/136638413-6a11fc05-69c7-4c57-9dee-b61b92caadae.png)
   
   这样构造出来的URL就符合期望了,而且这里是直接替换掉url上面的请求参数,因此我认为DividePlugin里面追加query参数的步骤都是可以省略的
   ![image](https://user-images.githubusercontent.com/54448899/136638463-de2cbd70-ea03-411d-b4c4-5dad25d7b807.png)
   
   另外,我在测试的时候,如果参数是%的话还是有问题,不使用Soul也是有问题的,这个可能是Tomcat的问题吧...
   
   对于昨天提出的没有经过详细验证的方案我很抱歉,不好意思挖坑了🤣
   
   @qicz 


-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org