Class PredicateSpec
- java.lang.Object
-
- org.springframework.cloud.gateway.route.builder.UriSpec
-
- org.springframework.cloud.gateway.route.builder.PredicateSpec
-
- Direct Known Subclasses:
BooleanSpec.BooleanOpSpec
public class PredicateSpec extends UriSpec
Predicates that can be applied to a URI route.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BooleanSpec
after(ZonedDateTime datetime)
A predicate to check if a request was made after a specificZonedDateTime
.BooleanSpec
alwaysTrue()
A predicate which is always true.BooleanSpec
asyncPredicate(AsyncPredicate<org.springframework.web.server.ServerWebExchange> predicate)
BooleanSpec
before(ZonedDateTime datetime)
A predicate to check if a request was made before a specificZonedDateTime
.BooleanSpec
between(ZonedDateTime datetime1, ZonedDateTime datetime2)
A predicate to check if a request was made between twoZonedDateTime
s.BooleanSpec
cloudFoundryRouteService()
BooleanSpec
cookie(String name, String regex)
A predicate that checks if a cookie matches a given regular expression.protected GatewayFilterSpec
createGatewayFilterSpec()
BooleanSpec
header(String header)
A predicate that checks if a given header is present on the request.BooleanSpec
header(String header, String regex)
A predicate that checks if a given headers has a value which matches a regular expression.BooleanSpec
host(String... pattern)
A predicate that checks if thehost
header matches a given pattern.BooleanSpec
method(String... methods)
A predicate that checks if the HTTP method matches.BooleanSpec
method(org.springframework.http.HttpMethod... methods)
A predicate that checks if the HTTP method matches.BooleanSpec
not(Function<PredicateSpec,BooleanSpec> fn)
PredicateSpec
order(int order)
BooleanSpec
path(boolean matchTrailingSlash, String... patterns)
A predicate that checks if the path of the request matches the given pattern.BooleanSpec
path(String... patterns)
A predicate that checks if the path of the request matches the given pattern.BooleanSpec
predicate(Predicate<org.springframework.web.server.ServerWebExchange> predicate)
BooleanSpec
query(String param)
A predicate that checks if a given query parameter is present in the request URL.BooleanSpec
query(String param, String regex)
A predicate that checks if a query parameter matches a regular expression.<T> BooleanSpec
readBody(Class<T> inClass, Predicate<T> predicate)
This predicate is BETA and may be subject to change in a future release.BooleanSpec
remoteAddr(String... addrs)
A predicate which checks the remote address of the request.BooleanSpec
remoteAddr(RemoteAddressResolver resolver, String... addrs)
A predicate which checks the remote address of the request.BooleanSpec
weight(String group, int weight)
A predicate which will select a route based on its assigned weight.BooleanSpec
xForwardedRemoteAddr(String... addrs)
A predicate which checks the remote address of the request based off of theX-Forwarded-For
header.
-
-
-
Method Detail
-
order
public PredicateSpec order(int order)
-
predicate
public BooleanSpec predicate(Predicate<org.springframework.web.server.ServerWebExchange> predicate)
-
asyncPredicate
public BooleanSpec asyncPredicate(AsyncPredicate<org.springframework.web.server.ServerWebExchange> predicate)
-
createGatewayFilterSpec
protected GatewayFilterSpec createGatewayFilterSpec()
-
after
public BooleanSpec after(ZonedDateTime datetime)
A predicate to check if a request was made after a specificZonedDateTime
.- Parameters:
datetime
- requests would only be routed after thisZonedDateTime
- Returns:
- a
BooleanSpec
to be used to add logical operators
-
before
public BooleanSpec before(ZonedDateTime datetime)
A predicate to check if a request was made before a specificZonedDateTime
.- Parameters:
datetime
- requests will only be routed before thisZonedDateTime
- Returns:
- a
BooleanSpec
to be used to add logical operators
-
between
public BooleanSpec between(ZonedDateTime datetime1, ZonedDateTime datetime2)
A predicate to check if a request was made between twoZonedDateTime
s.- Parameters:
datetime1
- the request must have been made after thisZonedDateTime
datetime2
- the request must be made before thisZonedDateTime
- Returns:
- a
BooleanSpec
to be used to add logical operators
-
cookie
public BooleanSpec cookie(String name, String regex)
A predicate that checks if a cookie matches a given regular expression.- Parameters:
name
- the name of the cookieregex
- the value of the cookies will be evaluated against this regular expression- Returns:
- a
BooleanSpec
to be used to add logical operators
-
header
public BooleanSpec header(String header)
A predicate that checks if a given header is present on the request.- Parameters:
header
- the header name to check- Returns:
- a
BooleanSpec
to be used to add logical operators
-
header
public BooleanSpec header(String header, String regex)
A predicate that checks if a given headers has a value which matches a regular expression.- Parameters:
header
- the header name to checkregex
- the regular expression to check against- Returns:
- a
BooleanSpec
to be used to add logical operators
-
host
public BooleanSpec host(String... pattern)
A predicate that checks if thehost
header matches a given pattern.- Parameters:
pattern
- the pattern to check against. The pattern is an Ant style pattern with.
as a separator- Returns:
- a
BooleanSpec
to be used to add logical operators
-
method
public BooleanSpec method(String... methods)
A predicate that checks if the HTTP method matches.- Parameters:
methods
- the name of the HTTP methods- Returns:
- a
BooleanSpec
to be used to add logical operators
-
method
public BooleanSpec method(org.springframework.http.HttpMethod... methods)
A predicate that checks if the HTTP method matches.- Parameters:
methods
- the HTTP methods- Returns:
- a
BooleanSpec
to be used to add logical operators
-
path
public BooleanSpec path(String... patterns)
A predicate that checks if the path of the request matches the given pattern.- Parameters:
patterns
- the pattern to check the path against. The pattern is aPathMatcher
pattern- Returns:
- a
BooleanSpec
to be used to add logical operators
-
path
public BooleanSpec path(boolean matchTrailingSlash, String... patterns)
A predicate that checks if the path of the request matches the given pattern.- Parameters:
patterns
- the pattern to check the path against. The pattern is aPathMatcher
patternmatchTrailingSlash
- set to false if you do not want this path to match when there is a trailing/
- Returns:
- a
BooleanSpec
to be used to add logical operators
-
readBody
public <T> BooleanSpec readBody(Class<T> inClass, Predicate<T> predicate)
This predicate is BETA and may be subject to change in a future release. A predicate that checks the contents of the request body- Type Parameters:
T
- the type the body is parsed to- Parameters:
inClass
- the class to parse the body topredicate
- a predicate to check the contents of the body- Returns:
- a
BooleanSpec
to be used to add logical operators
-
query
public BooleanSpec query(String param, String regex)
A predicate that checks if a query parameter matches a regular expression.- Parameters:
param
- the query parameter nameregex
- the regular expression to evaluate the query parameter value against- Returns:
- a
BooleanSpec
to be used to add logical operators
-
query
public BooleanSpec query(String param)
A predicate that checks if a given query parameter is present in the request URL.- Parameters:
param
- the query parameter name- Returns:
- a
BooleanSpec
to be used to add logical operators
-
remoteAddr
public BooleanSpec remoteAddr(String... addrs)
A predicate which checks the remote address of the request. By default the RemoteAddr Route Predicate Factory uses the remote address from the incoming request. This may not match the actual client IP address if Spring Cloud Gateway sits behind a proxy layer. UseremoteAddr(RemoteAddressResolver, String...)
to customize the resolver. You can customize the way that the remote address is resolved by setting a custom RemoteAddressResolver.- Parameters:
addrs
- the remote address to verify. Should use CIDR-notation (IPv4 or IPv6) strings.- Returns:
- a
BooleanSpec
to be used to add logical operators
-
remoteAddr
public BooleanSpec remoteAddr(RemoteAddressResolver resolver, String... addrs)
A predicate which checks the remote address of the request. Useful if Spring Cloud Gateway site behind a proxy layer. Spring Cloud Gateway comes with one non-default remote address resolver which is based off of theX-Forwarded-For
header,XForwardedRemoteAddressResolver
. SeeXForwardedRemoteAddressResolver
for more information.- Parameters:
resolver
- theRemoteAddressResolver
to use to resolve the remote IP address againstaddrs
- the remote address to verify. Should use CIDR-notation (IPv4 or IPv6) strings.- Returns:
- a
BooleanSpec
to be used to add logical operators
-
xForwardedRemoteAddr
public BooleanSpec xForwardedRemoteAddr(String... addrs)
A predicate which checks the remote address of the request based off of theX-Forwarded-For
header. Useful if Spring Cloud Gateway site behind a proxy layer. SeeXForwardedRemoteAddressResolver
for more information.- Parameters:
addrs
- the remote address to verify. Should use CIDR-notation (IPv4 or IPv6) strings.- Returns:
- a
BooleanSpec
to be used to add logical operators
-
weight
public BooleanSpec weight(String group, int weight)
A predicate which will select a route based on its assigned weight.- Parameters:
group
- the group the route belongs toweight
- the weight for the route- Returns:
- a
BooleanSpec
to be used to add logical operators
-
cloudFoundryRouteService
public BooleanSpec cloudFoundryRouteService()
-
alwaysTrue
public BooleanSpec alwaysTrue()
A predicate which is always true.- Returns:
- a
BooleanSpec
to be used to add logical operators
-
not
public BooleanSpec not(Function<PredicateSpec,BooleanSpec> fn)
-
-