Class RequestPredicates
- java.lang.Object
- org.springframework.web.servlet.function.RequestPredicates
 
- public abstract class RequestPredicates extends Object Implementations of- RequestPredicatethat implement various useful request matching operations, such as matching based on path, HTTP method, etc.- Since:
- 5.2
- Author:
- Arjen Poutsma
 
- Nested Class Summary- Nested Classes - Modifier and Type - Class - Description - static interface- RequestPredicates.VisitorReceives notifications from the logical structure of request predicates.
 - Constructor Summary- Constructors - Constructor - Description - RequestPredicates()
 - Method Summary- All Methods Static Methods Concrete Methods - Modifier and Type - Method - Description - static RequestPredicate- accept(MediaType... mediaTypes)Return a- RequestPredicatethat tests if the request's accept header is compatible with any of the given media types.- static RequestPredicate- all()Return a- RequestPredicatethat always matches.- static RequestPredicate- contentType(MediaType... mediaTypes)Return a- RequestPredicatethat tests if the request's content type is included by any of the given media types.- static RequestPredicate- DELETE(String pattern)Return a- RequestPredicatethat matches if request's HTTP method is- DELETEand the given- patternmatches against the request path.- static RequestPredicate- GET(String pattern)Return a- RequestPredicatethat matches if request's HTTP method is- GETand the given- patternmatches against the request path.- static RequestPredicate- HEAD(String pattern)Return a- RequestPredicatethat matches if request's HTTP method is- HEADand the given- patternmatches against the request path.- static RequestPredicate- headers(Predicate<ServerRequest.Headers> headersPredicate)Return a- RequestPredicatethat tests the request's headers against the given headers predicate.- static RequestPredicate- method(HttpMethod httpMethod)Return a- RequestPredicatethat matches if the request's HTTP method is equal to the given method.- static RequestPredicate- methods(HttpMethod... httpMethods)Return a- RequestPredicatethat matches if the request's HTTP method is equal to one the of the given methods.- static RequestPredicate- OPTIONS(String pattern)Return a- RequestPredicatethat matches if request's HTTP method is- OPTIONSand the given- patternmatches against the request path.- static RequestPredicate- param(String name, String value)Return a- RequestPredicatethat matches if the request's parameter of the given name has the given value.- static RequestPredicate- param(String name, Predicate<String> predicate)Return a- RequestPredicatethat tests the request's parameter of the given name against the given predicate.- static RequestPredicate- PATCH(String pattern)Return a- RequestPredicatethat matches if request's HTTP method is- PATCHand the given- patternmatches against the request path.- static RequestPredicate- path(String pattern)Return a- RequestPredicatethat tests the request path against the given path pattern.- static RequestPredicate- pathExtension(String extension)Return a- RequestPredicatethat matches if the request's path has the given extension.- static RequestPredicate- pathExtension(Predicate<String> extensionPredicate)Return a- RequestPredicatethat matches if the request's path matches the given predicate.- static Function<String,RequestPredicate>- pathPredicates(PathPatternParser patternParser)Return a function that creates new path-matching- RequestPredicatesfrom pattern Strings using the given- PathPatternParser.- static RequestPredicate- POST(String pattern)Return a- RequestPredicatethat matches if request's HTTP method is- POSTand the given- patternmatches against the request path.- static RequestPredicate- PUT(String pattern)Return a- RequestPredicatethat matches if request's HTTP method is- PUTand the given- patternmatches against the request path.
 
- Constructor Detail- RequestPredicates- public RequestPredicates() 
 
 - Method Detail- all- public static RequestPredicate all() Return a- RequestPredicatethat always matches.- Returns:
- a predicate that always matches
 
 - method- public static RequestPredicate method(HttpMethod httpMethod) Return a- RequestPredicatethat 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- public static RequestPredicate methods(HttpMethod... httpMethods) Return a- RequestPredicatethat 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
 
 - path- public static RequestPredicate path(String pattern) Return a- RequestPredicatethat 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
 
 - pathPredicates- public static Function<String,RequestPredicate> pathPredicates(PathPatternParser patternParser) Return a function that creates new path-matching- RequestPredicatesfrom pattern Strings using the given- PathPatternParser.- 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- public static RequestPredicate headers(Predicate<ServerRequest.Headers> headersPredicate) Return a- RequestPredicatethat 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- public static RequestPredicate contentType(MediaType... mediaTypes) Return a- RequestPredicatethat 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- public static RequestPredicate accept(MediaType... mediaTypes) Return a- RequestPredicatethat 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- public static RequestPredicate GET(String pattern) Return a- RequestPredicatethat matches if request's HTTP method is- GETand the given- patternmatches 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
 
 - HEAD- public static RequestPredicate HEAD(String pattern) Return a- RequestPredicatethat matches if request's HTTP method is- HEADand the given- patternmatches 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
 
 - POST- public static RequestPredicate POST(String pattern) Return a- RequestPredicatethat matches if request's HTTP method is- POSTand the given- patternmatches 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
 
 - PUT- public static RequestPredicate PUT(String pattern) Return a- RequestPredicatethat matches if request's HTTP method is- PUTand the given- patternmatches 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
 
 - PATCH- public static RequestPredicate PATCH(String pattern) Return a- RequestPredicatethat matches if request's HTTP method is- PATCHand the given- patternmatches 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
 
 - DELETE- public static RequestPredicate DELETE(String pattern) Return a- RequestPredicatethat matches if request's HTTP method is- DELETEand the given- patternmatches 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
 
 - OPTIONS- public static RequestPredicate OPTIONS(String pattern) Return a- RequestPredicatethat matches if request's HTTP method is- OPTIONSand the given- patternmatches 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
 
 - pathExtension- public static RequestPredicate pathExtension(String extension) Return a- RequestPredicatethat 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- public static RequestPredicate pathExtension(Predicate<String> extensionPredicate) Return a- RequestPredicatethat 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
 
 - param- public static RequestPredicate param(String name, String value) Return a- RequestPredicatethat matches if the request's parameter of the given name has the given value.- Parameters:
- name- the name of the parameter to test against
- value- the value of the parameter to test against
- Returns:
- a predicate that matches if the parameter has the given value
- See Also:
- ServerRequest.param(String)
 
 - param- public static RequestPredicate param(String name, Predicate<String> predicate) Return a- RequestPredicatethat tests the request's parameter of the given name against the given predicate.- Parameters:
- name- the name of the parameter to test against
- predicate- the predicate to test against the parameter value
- Returns:
- a predicate that matches the given predicate against the parameter of the given name
- See Also:
- ServerRequest.param(String)