Spring Cloud Gateway Predicate 中的 matchOptionalTrailingSeparator 有什么用
What's the use of matchOptionalTrailingSeparator in Spring Cloud Gateway Predicate
来自 Spring Cloud Spring.io 给出的文档:
The Path Route Predicate Factory takes two parameters: a list of Spring PathMatcher patterns and an optional flag called matchOptionalTrailingSeparator.
它提到了一个可选标志 matchOptionalTrailingSeparator
,但没有更多描述。
这个标志有什么用,如何使用这个标志?
谢谢
参数 matchOptionalTrailingSeparator
用于确定给定的 Path 谓词是否也应匹配带有尾部斜杠 /
的请求。
默认情况下,这个值是true
.
例如路线下方
spring:
cloud:
gateway:
routes:
- id: host_route
uri: https://example.org
predicates:
- Path=/foo/{segment}
将匹配请求 /foo/{segment}
和 /foo/{segment}/
但是如果写成:
spring:
cloud:
gateway:
routes:
- id: host_route
uri: https://example.org
predicates:
- Path=/foo/{segment},false
它不会匹配尾部斜杠 /
的请求,即它只会匹配 /foo/{segment}
而不会匹配 /foo/{segment}/
来自 Spring Cloud Spring.io 给出的文档:
The Path Route Predicate Factory takes two parameters: a list of Spring PathMatcher patterns and an optional flag called matchOptionalTrailingSeparator.
它提到了一个可选标志 matchOptionalTrailingSeparator
,但没有更多描述。
这个标志有什么用,如何使用这个标志? 谢谢
参数 matchOptionalTrailingSeparator
用于确定给定的 Path 谓词是否也应匹配带有尾部斜杠 /
的请求。
默认情况下,这个值是true
.
例如路线下方
spring:
cloud:
gateway:
routes:
- id: host_route
uri: https://example.org
predicates:
- Path=/foo/{segment}
将匹配请求 /foo/{segment}
和 /foo/{segment}/
但是如果写成:
spring:
cloud:
gateway:
routes:
- id: host_route
uri: https://example.org
predicates:
- Path=/foo/{segment},false
它不会匹配尾部斜杠 /
的请求,即它只会匹配 /foo/{segment}
而不会匹配 /foo/{segment}/