Class RequestPredicates
java.lang.Object
org.springframework.web.reactive.function.server.RequestPredicates
Implementations of
RequestPredicate that implement various useful
request matching operations, such as matching based on path, HTTP method, etc.- Since:
- 5.0
- Author:
- Arjen Poutsma
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceReceives notifications from the logical structure of request predicates. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic RequestPredicateReturn aRequestPredicatethat tests if the request's accept header is compatible with any of the given media types.static RequestPredicateall()Return aRequestPredicatethat always matches.static RequestPredicatecontentType(MediaType... mediaTypes) Return aRequestPredicatethat tests if the request's content type is included by any of the given media types.static RequestPredicateReturn aRequestPredicatethat matches if request's HTTP method isDELETEand the givenpatternmatches against the request path.static RequestPredicateReturn aRequestPredicatethat matches if request's HTTP method isGETand the givenpatternmatches against the request path.static RequestPredicateReturn aRequestPredicatethat matches if request's HTTP method isHEADand the givenpatternmatches against the request path.static RequestPredicateheaders(Predicate<ServerRequest.Headers> headersPredicate) Return aRequestPredicatethat tests the request's headers against the given headers predicate.static RequestPredicatemethod(HttpMethod httpMethod) Return aRequestPredicatethat matches if the request's HTTP method is equal to the given method.static RequestPredicatemethods(HttpMethod... httpMethods) Return aRequestPredicatethat matches if the request's HTTP method is equal to one the of the given methods.static RequestPredicateReturn aRequestPredicatethat matches if request's HTTP method isOPTIONSand the givenpatternmatches against the request path.static RequestPredicateReturn aRequestPredicatethat matches if request's HTTP method isPATCHand the givenpatternmatches against the request path.static RequestPredicateReturn aRequestPredicatethat tests the request path against the given path pattern.static RequestPredicatepathExtension(String extension) Deprecated, for removal: This API element is subject to removal in a future version.without replacement to discourage use of path extensions for request mapping and for content negotiation (with similar deprecations and removals already applied to annotated controllers).static RequestPredicatepathExtension(Predicate<String> extensionPredicate) Deprecated, for removal: This API element is subject to removal in a future version.without replacement to discourage use of path extensions for request mapping and for content negotiation (with similar deprecations and removals already applied to annotated controllers).static Function<String,RequestPredicate> pathPredicates(PathPatternParser patternParser) Return a function that creates new path-matchingRequestPredicatesfrom pattern Strings using the givenPathPatternParser.static RequestPredicateReturn aRequestPredicatethat matches if request's HTTP method isPOSTand the givenpatternmatches against the request path.static RequestPredicateReturn aRequestPredicatethat matches if request's HTTP method isPUTand the givenpatternmatches against the request path.static RequestPredicatequeryParam(String name, String value) Return aRequestPredicatethat matches if the request's query parameter of the given name has the given value.static RequestPredicatequeryParam(String name, Predicate<String> predicate) Return aRequestPredicatethat tests the request's query parameter of the given name against the given predicate.
-
Constructor Details
-
RequestPredicates
public RequestPredicates()
-
-
Method Details
-
all
Return aRequestPredicatethat always matches.- Returns:
- a predicate that always matches
-
method
Return aRequestPredicatethat matches if the request's HTTP method is equal to the given method.- Parameters:
httpMethod- the HTTP method to match against- Returns:
- a predicate that tests against the given HTTP method
-
methods
Return aRequestPredicatethat matches if the request's HTTP method is equal to one the of the given methods.- Parameters:
httpMethods- the HTTP methods to match against- Returns:
- a predicate that tests against the given HTTP methods
- Since:
- 5.1
-
path
Return aRequestPredicatethat tests the request path against the given path pattern.- Parameters:
pattern- the pattern to match to- Returns:
- a predicate that tests against the given path pattern
- See Also:
-
pathPredicates
Return a function that creates new path-matchingRequestPredicatesfrom pattern Strings using the givenPathPatternParser.This method can be used to specify a non-default, customized
PathPatternParserwhen resolving path patterns.- Parameters:
patternParser- the parser used to parse patterns given to the returned function- Returns:
- a function that resolves a pattern String into a path-matching
RequestPredicatesinstance
-
headers
Return aRequestPredicatethat tests the request's headers against the given headers predicate.- Parameters:
headersPredicate- a predicate that tests against the request headers- Returns:
- a predicate that tests against the given header predicate
-
contentType
Return aRequestPredicatethat tests if the request's content type is included by any of the given media types.- Parameters:
mediaTypes- the media types to match the request's content type against- Returns:
- a predicate that tests the request's content type against the given media types
-
accept
Return aRequestPredicatethat tests if the request's accept header is compatible with any of the given media types.- Parameters:
mediaTypes- the media types to match the request's accept header against- Returns:
- a predicate that tests the request's accept header against the given media types
-
GET
Return aRequestPredicatethat matches if request's HTTP method isGETand the givenpatternmatches against the request path.- Parameters:
pattern- the path pattern to match against- Returns:
- a predicate that matches if the request method is GET and if the given pattern matches against the request path
- See Also:
-
HEAD
Return aRequestPredicatethat matches if request's HTTP method isHEADand the givenpatternmatches against the request path.- Parameters:
pattern- the path pattern to match against- Returns:
- a predicate that matches if the request method is HEAD and if the given pattern matches against the request path
- See Also:
-
POST
Return aRequestPredicatethat matches if request's HTTP method isPOSTand the givenpatternmatches against the request path.- Parameters:
pattern- the path pattern to match against- Returns:
- a predicate that matches if the request method is POST and if the given pattern matches against the request path
- See Also:
-
PUT
Return aRequestPredicatethat matches if request's HTTP method isPUTand the givenpatternmatches against the request path.- Parameters:
pattern- the path pattern to match against- Returns:
- a predicate that matches if the request method is PUT and if the given pattern matches against the request path
- See Also:
-
PATCH
Return aRequestPredicatethat matches if request's HTTP method isPATCHand the givenpatternmatches against the request path.- Parameters:
pattern- the path pattern to match against- Returns:
- a predicate that matches if the request method is PATCH and if the given pattern matches against the request path
- See Also:
-
DELETE
Return aRequestPredicatethat matches if request's HTTP method isDELETEand the givenpatternmatches against the request path.- Parameters:
pattern- the path pattern to match against- Returns:
- a predicate that matches if the request method is DELETE and if the given pattern matches against the request path
- See Also:
-
OPTIONS
Return aRequestPredicatethat matches if request's HTTP method isOPTIONSand the givenpatternmatches against the request path.- Parameters:
pattern- the path pattern to match against- Returns:
- a predicate that matches if the request method is OPTIONS and if the given pattern matches against the request path
- See Also:
-
pathExtension
@Deprecated(since="7.0", forRemoval=true) public static RequestPredicate pathExtension(String extension) Deprecated, for removal: This API element is subject to removal in a future version.without replacement to discourage use of path extensions for request mapping and for content negotiation (with similar deprecations and removals already applied to annotated controllers). For further context, please read issue #24179Return aRequestPredicatethat matches if the request's path has the given extension.- Parameters:
extension- the path extension to match against, ignoring case- Returns:
- a predicate that matches if the request's path has the given file extension
-
pathExtension
@Deprecated(since="7.0", forRemoval=true) public static RequestPredicate pathExtension(Predicate<String> extensionPredicate) Deprecated, for removal: This API element is subject to removal in a future version.without replacement to discourage use of path extensions for request mapping and for content negotiation (with similar deprecations and removals already applied to annotated controllers). For further context, please read issue #24179Return aRequestPredicatethat matches if the request's path matches the given predicate.- Parameters:
extensionPredicate- the predicate to test against the request path extension- Returns:
- a predicate that matches if the given predicate matches against the request's path file extension
-
queryParam
Return aRequestPredicatethat matches if the request's query parameter of the given name has the given value.- Parameters:
name- the name of the query parameter to test againstvalue- the value of the query parameter to test against- Returns:
- a predicate that matches if the query parameter has the given value
- Since:
- 5.0.7
- See Also:
-
queryParam
Return aRequestPredicatethat tests the request's query parameter of the given name against the given predicate.- Parameters:
name- the name of the query parameter to test againstpredicate- the predicate to test against the query parameter value- Returns:
- a predicate that matches the given predicate against the query parameter of the given name
- See Also:
-