URL 路径重写未按预期工作

时间:2021-01-30 06:10:52

标签: java url-rewriting spring-cloud spring-cloud-gateway

在将请求路由到正确的端点时,我有以下代码重写路径。但是,仍然使用完整 URL(原始)进行路由,而无需重写 URL。 类似类型的路径重写已用于另一个端点,工作正常。

代码

@Override
public Route.AsyncBuilder apply(PredicateSpec route) {
    return route
            .path("/api/out/**")
            .filters(f -> f
                    .removeRequestHeader("Cookie")
                    .filter(loggingGatewayFilter)
                    .filter(oauth2GatewayFilter)
                    .filter(this::filter)
                    .rewritePath("/api/out", "")
            )
            .uri(uri);
}

原始网址:http://external-url/api/out/xyz/data/getNext

预期结果:URL 路径将被重写为 http://external-url/xyz/data/getNext

但路由器仍在调用完整的 URL。

这里可能有什么问题? 服务器端/端点 (http://external-url) 中的任何配置都可能导致此问题

Spring Cloud 调试日志

+-------------------------------------------------+
| 0 1 2 3 4 5 6 7 8 9 a b c d e f |
+--------+-------------------------------------------------+----------------+
|00000000| 47 45 54 20 2f 76 31 2f 6f 6d 73 2f 74 72 61 6e |GET /xyz/data/get|
|00000010| 63 68 65 73 3f 70 61 67 65 3d 30 26 73 69 7a 65 |Next?page=0&size|
|00000020| 3d 31 30 30 26 63 72 65 61 74 65 64 42 65 66 6f |=100&createdBefo|
|00000030| 72 65 3d 32 30 32 31 2d 30 31 2d 32 39 54 32 33 |re=2021-01-29T23|
|00000040| 25 33 41 35 39 25 33 41 35 39 2e 39 39 39 25 32 |%3A59%3A59.999%2|
|00000050| 42 30 38 25 33 41 30 30 26 63 72 65 61 74 65 64 |B08%3A00&created|
|00000060| 41 66 74 65 72 3d 32 30 32 31 2d 30 31 2d 32 39 |After=2021-01-29|

0 个答案:

没有答案