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 Details

    • 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 specific ZonedDateTime.
      Parameters:
      datetime - requests would only be routed after this ZonedDateTime
      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 specific ZonedDateTime.
      Parameters:
      datetime - requests will only be routed before this ZonedDateTime
      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 two ZonedDateTimes.
      Parameters:
      datetime1 - the request must have been made after this ZonedDateTime
      datetime2 - the request must be made before this ZonedDateTime
      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 cookie
      regex - 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, @Nullable String regex)
      A predicate that checks if a given headers has a value which matches a regular expression.
      Parameters:
      header - the header name to check
      regex - 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 the host 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 a PathMatcher 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:
      matchTrailingSlash - set to false if you do not want this path to match when there is a trailing /
      patterns - the pattern to check the path against. The pattern is a PathMatcher pattern
      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 to
      predicate - 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, Predicate<String> predicate)
      A predicate that checks if a query parameter value matches criteria of a given predicate.
      Parameters:
      param - the query parameter name
      predicate - a predicate to check the value of the param
      Returns:
      a BooleanSpec to be used to add logical operators
    • query

      public BooleanSpec query(String param, @Nullable String regex)
      A predicate that checks if a query parameter matches a regular expression.
      Parameters:
      param - the query parameter name
      regex - 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. Use remoteAddr(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(@Nullable 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 the X-Forwarded-For header, XForwardedRemoteAddressResolver. See XForwardedRemoteAddressResolver for more information.
      Parameters:
      resolver - the RemoteAddressResolver to use to resolve the remote IP address against
      addrs - the remote address to verify. Should use CIDR-notation (IPv4 or IPv6) strings.
      Returns:
      a BooleanSpec to be used to add logical operators
    • version

      public BooleanSpec version(String version)
      A predicate that checks for the version specified. This uses the Spring Framework ApiStrategry.
      Parameters:
      version - the version to check.
      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 the X-Forwarded-For header. Useful if Spring Cloud Gateway site behind a proxy layer. See XForwardedRemoteAddressResolver 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 to
      weight - 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