public abstract class RequestPredicates
extends java.lang.Object
RequestPredicate
that implement various useful
request matching operations, such as matching based on path, HTTP method, etc.Modifier and Type | Class and Description |
---|---|
private static class |
RequestPredicates.AcceptPredicate |
(package private) static class |
RequestPredicates.AndRequestPredicate
|
private static class |
RequestPredicates.ContentTypePredicate |
private static class |
RequestPredicates.HeadersPredicate |
private static class |
RequestPredicates.HttpMethodPredicate |
(package private) static class |
RequestPredicates.NegateRequestPredicate
RequestPredicate that negates a delegate predicate. |
(package private) static class |
RequestPredicates.OrRequestPredicate
|
private static class |
RequestPredicates.ParamPredicate |
private static class |
RequestPredicates.PathExtensionPredicate |
private static class |
RequestPredicates.PathPatternPredicate |
private static class |
RequestPredicates.SubPathServerRequestWrapper |
static interface |
RequestPredicates.Visitor
Receives notifications from the logical structure of request predicates.
|
Modifier and Type | Field and Description |
---|---|
private static PathPatternParser |
DEFAULT_PATTERN_PARSER |
private static Log |
logger |
Constructor and Description |
---|
RequestPredicates() |
Modifier and Type | Method and Description |
---|---|
static RequestPredicate |
accept(MediaType... mediaTypes)
Return a
RequestPredicate that tests if the request's
accept header is
compatible with any of the given media types. |
static RequestPredicate |
all()
Return a
RequestPredicate that always matches. |
static RequestPredicate |
contentType(MediaType... mediaTypes)
Return a
RequestPredicate that tests if the request's
content type is
included by any of the given media types. |
static RequestPredicate |
DELETE(java.lang.String pattern)
Return a
RequestPredicate that matches if request's HTTP method is DELETE
and the given pattern matches against the request path. |
static RequestPredicate |
GET(java.lang.String pattern)
Return a
RequestPredicate that matches if request's HTTP method is GET
and the given pattern matches against the request path. |
static RequestPredicate |
HEAD(java.lang.String pattern)
Return a
RequestPredicate that matches if request's HTTP method is HEAD
and the given pattern matches against the request path. |
static RequestPredicate |
headers(java.util.function.Predicate<ServerRequest.Headers> headersPredicate)
Return a
RequestPredicate that tests the request's headers
against the given headers predicate. |
private static java.util.Map<java.lang.String,java.lang.String> |
mergePathVariables(java.util.Map<java.lang.String,java.lang.String> oldVariables,
java.util.Map<java.lang.String,java.lang.String> newVariables) |
private static PathPattern |
mergePatterns(PathPattern oldPattern,
PathPattern newPattern) |
static RequestPredicate |
method(HttpMethod httpMethod)
Return a
RequestPredicate that matches if the request's
HTTP method is equal to the given method. |
static RequestPredicate |
methods(HttpMethod... httpMethods)
Return a
RequestPredicate that matches if the request's
HTTP method is equal to one the of the given methods. |
static RequestPredicate |
OPTIONS(java.lang.String pattern)
Return a
RequestPredicate that matches if request's HTTP method is OPTIONS
and the given pattern matches against the request path. |
static RequestPredicate |
param(java.lang.String name,
java.util.function.Predicate<java.lang.String> predicate)
Return a
RequestPredicate that tests the request's parameter of the given name
against the given predicate. |
static RequestPredicate |
param(java.lang.String name,
java.lang.String value)
Return a
RequestPredicate that matches if the request's parameter of the given name
has the given value. |
static RequestPredicate |
PATCH(java.lang.String pattern)
Return a
RequestPredicate that matches if request's HTTP method is PATCH
and the given pattern matches against the request path. |
static RequestPredicate |
path(java.lang.String pattern)
Return a
RequestPredicate that tests the request path
against the given path pattern. |
static RequestPredicate |
pathExtension(java.util.function.Predicate<java.lang.String> extensionPredicate)
Return a
RequestPredicate that matches if the request's path matches the given
predicate. |
static RequestPredicate |
pathExtension(java.lang.String extension)
Return a
RequestPredicate that matches if the request's path has the given extension. |
static java.util.function.Function<java.lang.String,RequestPredicate> |
pathPredicates(PathPatternParser patternParser)
Return a function that creates new path-matching
RequestPredicates
from pattern Strings using the given PathPatternParser . |
static RequestPredicate |
POST(java.lang.String pattern)
Return a
RequestPredicate that matches if request's HTTP method is POST
and the given pattern matches against the request path. |
static RequestPredicate |
PUT(java.lang.String pattern)
Return a
RequestPredicate that matches if request's HTTP method is PUT
and the given pattern matches against the request path. |
private static void |
restoreAttributes(ServerRequest request,
java.util.Map<java.lang.String,java.lang.Object> attributes) |
private static void |
traceMatch(java.lang.String prefix,
java.lang.Object desired,
java.lang.Object actual,
boolean match) |
private static final Log logger
private static final PathPatternParser DEFAULT_PATTERN_PARSER
public static RequestPredicate all()
RequestPredicate
that always matches.public static RequestPredicate method(HttpMethod httpMethod)
RequestPredicate
that matches if the request's
HTTP method is equal to the given method.httpMethod
- the HTTP method to match againstpublic static RequestPredicate methods(HttpMethod... httpMethods)
RequestPredicate
that matches if the request's
HTTP method is equal to one the of the given methods.httpMethods
- the HTTP methods to match againstpublic static RequestPredicate path(java.lang.String pattern)
RequestPredicate
that tests the request path
against the given path pattern.pattern
- the pattern to match topublic static java.util.function.Function<java.lang.String,RequestPredicate> pathPredicates(PathPatternParser patternParser)
RequestPredicates
from pattern Strings using the given PathPatternParser
.
This method can be used to specify a non-default, customized
PathPatternParser
when resolving path patterns.
patternParser
- the parser used to parse patterns given to the returned functionRequestPredicates
instancepublic static RequestPredicate headers(java.util.function.Predicate<ServerRequest.Headers> headersPredicate)
RequestPredicate
that tests the request's headers
against the given headers predicate.headersPredicate
- a predicate that tests against the request headerspublic static RequestPredicate contentType(MediaType... mediaTypes)
RequestPredicate
that tests if the request's
content type is
included by any of the given media types.mediaTypes
- the media types to match the request's content type againstpublic static RequestPredicate accept(MediaType... mediaTypes)
RequestPredicate
that tests if the request's
accept header is
compatible with any of the given media types.mediaTypes
- the media types to match the request's accept header againstpublic static RequestPredicate GET(java.lang.String pattern)
RequestPredicate
that matches if request's HTTP method is GET
and the given pattern
matches against the request path.pattern
- the path pattern to match againstpublic static RequestPredicate HEAD(java.lang.String pattern)
RequestPredicate
that matches if request's HTTP method is HEAD
and the given pattern
matches against the request path.pattern
- the path pattern to match againstpublic static RequestPredicate POST(java.lang.String pattern)
RequestPredicate
that matches if request's HTTP method is POST
and the given pattern
matches against the request path.pattern
- the path pattern to match againstpublic static RequestPredicate PUT(java.lang.String pattern)
RequestPredicate
that matches if request's HTTP method is PUT
and the given pattern
matches against the request path.pattern
- the path pattern to match againstpublic static RequestPredicate PATCH(java.lang.String pattern)
RequestPredicate
that matches if request's HTTP method is PATCH
and the given pattern
matches against the request path.pattern
- the path pattern to match againstpublic static RequestPredicate DELETE(java.lang.String pattern)
RequestPredicate
that matches if request's HTTP method is DELETE
and the given pattern
matches against the request path.pattern
- the path pattern to match againstpublic static RequestPredicate OPTIONS(java.lang.String pattern)
RequestPredicate
that matches if request's HTTP method is OPTIONS
and the given pattern
matches against the request path.pattern
- the path pattern to match againstpublic static RequestPredicate pathExtension(java.lang.String extension)
RequestPredicate
that matches if the request's path has the given extension.extension
- the path extension to match against, ignoring casepublic static RequestPredicate pathExtension(java.util.function.Predicate<java.lang.String> extensionPredicate)
RequestPredicate
that matches if the request's path matches the given
predicate.extensionPredicate
- the predicate to test against the request path extensionpublic static RequestPredicate param(java.lang.String name, java.lang.String value)
RequestPredicate
that matches if the request's parameter of the given name
has the given value.name
- the name of the parameter to test againstvalue
- the value of the parameter to test againstServerRequest.param(String)
public static RequestPredicate param(java.lang.String name, java.util.function.Predicate<java.lang.String> predicate)
RequestPredicate
that tests the request's parameter of the given name
against the given predicate.name
- the name of the parameter to test againstpredicate
- predicate to test against the parameter valueServerRequest.param(String)
private static void traceMatch(java.lang.String prefix, java.lang.Object desired, @Nullable java.lang.Object actual, boolean match)
private static void restoreAttributes(ServerRequest request, java.util.Map<java.lang.String,java.lang.Object> attributes)
private static java.util.Map<java.lang.String,java.lang.String> mergePathVariables(java.util.Map<java.lang.String,java.lang.String> oldVariables, java.util.Map<java.lang.String,java.lang.String> newVariables)
private static PathPattern mergePatterns(@Nullable PathPattern oldPattern, PathPattern newPattern)