From the doc about Spring Cloud that Spring.io given:
The Path Route Predicate Factory takes two parameters: a list of Spring PathMatcher patterns and an optional flag called matchOptionalTrailingSeparator.
It mentions an optional flag matchOptionalTrailingSeparator
without more description.
What is the use of this flag and how to use this flag? Thanks
The parameter matchOptionalTrailingSeparator
is used to determine whether the given Path predicate should also match the requests with the trailing slash /
too.
By default, the value of this is true
.
For e.g. below route
spring:
cloud:
gateway:
routes:
- id: host_route
uri: https://example.org
predicates:
- Path=/foo/{segment}
will match both the request /foo/{segment}
and /foo/{segment}/
But if it's written as:
spring:
cloud:
gateway:
routes:
- id: host_route
uri: https://example.org
predicates:
- Path=/foo/{segment},false
It will not match the requests with trailing slash /
i.e. it will only match /foo/{segment}
and not match /foo/{segment}/