You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
In the public Predicate<ServerWebExchange> org.springframework.cloud.gateway.handler.predicate.HeaderRoutePredicateFactory.test(Config) method, the anonymous GatewayPredicate class should use List<String> HttpHeaders.getValuesAsList(String) instead of List<String> HttpHeaders.getOrDefault(String, List<String>).
The current implementation using List<String> HttpHeaders.getOrDefault(String, List<String>) provides multiple values as a single String connected by ','. To find "a match among multiple values" using a regexp, one would need to provide an input like ^(.*,\s?)*exact_match(,\s.*)$. If parsing headers containing spaces or ',' is required, it becomes even more complex as they need to be wrapped in quotation marks.
As explained in the annotation of the List<String> HttpHeaders.getValuesAsList(String) method, RFC 9110, section 5.5 defines ',' as a delimiter between members.
The current implementation is valid for 'singleton fields' but not for 'list-based fields'. Since the results may vary depending on the request client or the proxy used, we propose this change.
This issue affects Spring Cloud Gateway, current version.
Sample
Here's a sample application that reproduces the problem:
# This works as expected
curl http://localhost:8080/test -H "X-Test-Header: test-value"# Output: Route matched# This fails to match the intended route and triggers the fallback
curl http://localhost:8080/test -H "X-Test-Header: test-value, another-value"# Output: Route not matched, fallback triggered# This works as expected
curl http://localhost:8080/test -H "X-Test-Header: test-value" -H "X-Test-Header: another-value"# Output: Route matched
The second request should match the "test-header-route" and return "Route matched", just like the first and third requests. However, it fails to match the intended route due to the current implementation of HeaderRoutePredicateFactory, causing the request to be handled by the catch-all route.
The text was updated successfully, but these errors were encountered:
Describe the bug
In the
public Predicate<ServerWebExchange> org.springframework.cloud.gateway.handler.predicate.HeaderRoutePredicateFactory.test(Config)
method, the anonymousGatewayPredicate
class should useList<String> HttpHeaders.getValuesAsList(String)
instead ofList<String> HttpHeaders.getOrDefault(String, List<String>)
.The current implementation using
List<String> HttpHeaders.getOrDefault(String, List<String>)
provides multiple values as a single String connected by ','. To find "a match among multiple values" using a regexp, one would need to provide an input like^(.*,\s?)*exact_match(,\s.*)$
. If parsing headers containing spaces or ',' is required, it becomes even more complex as they need to be wrapped in quotation marks.As explained in the annotation of the
List<String> HttpHeaders.getValuesAsList(String)
method, RFC 9110, section 5.5 defines ',' as a delimiter between members.The current implementation is valid for 'singleton fields' but not for 'list-based fields'. Since the results may vary depending on the request client or the proxy used, we propose this change.
This issue affects Spring Cloud Gateway, current version.
Sample
Here's a sample application that reproduces the problem:
Test calls:
The second request should match the "test-header-route" and return "Route matched", just like the first and third requests. However, it fails to match the intended route due to the current implementation of HeaderRoutePredicateFactory, causing the request to be handled by the catch-all route.
The text was updated successfully, but these errors were encountered: