Class HttpPredicateRouterBuilder
java.lang.Object
io.servicetalk.http.router.predicate.HttpPredicateRouterBuilder
- All Implemented Interfaces:
RouteStarter
Builds a
StreamingHttpService
which routes requests to a number of other StreamingHttpService
s based
on user specified criteria.
eg.
final StreamingHttpService<HttpChunk, HttpChunk> router = new HttpPredicateRouterBuilder<HttpChunk, HttpChunk>()
.whenMethod(GET).andPathStartsWith("/a/").thenRouteTo(serviceA)
.whenMethod(GET).andPathStartsWith("/b/").thenRouteTo(serviceB)
.whenMethod(POST).thenRouteTo(serviceC)
.buildStreaming();
If no routes match, a default service is used, which returns a 404 response.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionBuilds theStreamingHttpService
that performs the configured routing.when
(BiPredicate<ConnectionContext, StreamingHttpRequest> predicate) Begin a route that matchesStreamingHttpRequest
andConnectionContext
with a user-specifiedpredicate
.when
(Predicate<StreamingHttpRequest> predicate) Begin a route that matchesStreamingHttpRequest
s with a user-specifiedpredicate
.whenCookie
(String name) whenHeader
(CharSequence name) Begin a route with aStringMultiValueMatcher
that matches against the value(s) of thename
headers.Begin a route that matches requests that are not over SSL/TLS.Begin a route that matches requests that are over SSL/TLS.whenMethod
(HttpRequestMethod method) Begin a route that matches requests where theHttpRequestMethod
ismethod
.whenMethodIsOneOf
(HttpRequestMethod... methods) Begin a route that matches requests where theHttpRequestMethod
is one of themethods
.whenPathEquals
(String path) Begin a route that matches requests where the path is equal topath
.whenPathIsOneOf
(String... paths) Begin a route that matches requests where the path is equal to any of the specifiedpath
s.whenPathMatches
(String pathRegex) Begin a route that matches requests where the path matches the regexpathRegex
.whenPathMatches
(Pattern pathRegex) Begin a route that matches requests where the path matches the regexpathRegex
.whenPathStartsWith
(String pathPrefix) Begin a route that matches requests where the path starts withpathPrefix
.whenQueryParam
(String name) Begin a route with aStringMultiValueMatcher
that matches against the value(s) of the request parametername
.
-
Constructor Details
-
HttpPredicateRouterBuilder
public HttpPredicateRouterBuilder()
-
-
Method Details
-
whenMethod
Description copied from interface:RouteStarter
Begin a route that matches requests where theHttpRequestMethod
ismethod
.- Specified by:
whenMethod
in interfaceRouteStarter
- Parameters:
method
- the method to match.- Returns:
RouteContinuation
for the next steps of building a route.
-
whenMethodIsOneOf
Description copied from interface:RouteStarter
Begin a route that matches requests where theHttpRequestMethod
is one of themethods
.- Specified by:
whenMethodIsOneOf
in interfaceRouteStarter
- Parameters:
methods
- the methods to match.- Returns:
RouteContinuation
for the next steps of building a route.
-
whenPathEquals
Description copied from interface:RouteStarter
Begin a route that matches requests where the path is equal topath
.- Specified by:
whenPathEquals
in interfaceRouteStarter
- Parameters:
path
- the path to match.- Returns:
RouteContinuation
for the next steps of building a route.
-
whenPathIsOneOf
Description copied from interface:RouteStarter
Begin a route that matches requests where the path is equal to any of the specifiedpath
s.- Specified by:
whenPathIsOneOf
in interfaceRouteStarter
- Parameters:
paths
- the paths to match.- Returns:
RouteContinuation
for the next steps of building a route.
-
whenPathStartsWith
Description copied from interface:RouteStarter
Begin a route that matches requests where the path starts withpathPrefix
.- Specified by:
whenPathStartsWith
in interfaceRouteStarter
- Parameters:
pathPrefix
- the path prefix to match.- Returns:
RouteContinuation
for the next steps of building a route.
-
whenPathMatches
Description copied from interface:RouteStarter
Begin a route that matches requests where the path matches the regexpathRegex
.- Specified by:
whenPathMatches
in interfaceRouteStarter
- Parameters:
pathRegex
- the regex to match against the request path.- Returns:
RouteContinuation
for the next steps of building a route.
-
whenPathMatches
Description copied from interface:RouteStarter
Begin a route that matches requests where the path matches the regexpathRegex
.- Specified by:
whenPathMatches
in interfaceRouteStarter
- Parameters:
pathRegex
- the regex to match against the request path.- Returns:
RouteContinuation
for the next steps of building a route.
-
whenQueryParam
Description copied from interface:RouteStarter
Begin a route with aStringMultiValueMatcher
that matches against the value(s) of the request parametername
.- Specified by:
whenQueryParam
in interfaceRouteStarter
- Parameters:
name
- the request parameter name that must be present in the request in order to continue evaluation of this route.- Returns:
StringMultiValueMatcher
for the next steps of building a route.
-
whenHeader
Description copied from interface:RouteStarter
Begin a route with aStringMultiValueMatcher
that matches against the value(s) of thename
headers.- Specified by:
whenHeader
in interfaceRouteStarter
- Parameters:
name
- The header name that must be present in the request in order to continue evaluation of this route.- Returns:
StringMultiValueMatcher
for the next steps of building a route.
-
whenCookie
Description copied from interface:RouteStarter
- Specified by:
whenCookie
in interfaceRouteStarter
- Parameters:
name
- the cookie name that must be present in the request in order to continue evaluation of this route.- Returns:
CookieMatcher
for the next steps of building a route.
-
whenIsSsl
Description copied from interface:RouteStarter
Begin a route that matches requests that are over SSL/TLS.- Specified by:
whenIsSsl
in interfaceRouteStarter
- Returns:
RouteContinuation
for the next steps of building a route.
-
whenIsNotSsl
Description copied from interface:RouteStarter
Begin a route that matches requests that are not over SSL/TLS.- Specified by:
whenIsNotSsl
in interfaceRouteStarter
- Returns:
RouteContinuation
for the next steps of building a route.
-
when
Description copied from interface:RouteStarter
Begin a route that matchesStreamingHttpRequest
s with a user-specifiedpredicate
.- Specified by:
when
in interfaceRouteStarter
- Parameters:
predicate
- the predicate to evaluate against requests.- Returns:
RouteContinuation
for the next steps of building a route.
-
when
Description copied from interface:RouteStarter
Begin a route that matchesStreamingHttpRequest
andConnectionContext
with a user-specifiedpredicate
.- Specified by:
when
in interfaceRouteStarter
- Parameters:
predicate
- the predicate to evaluate against the request and connection context.- Returns:
RouteContinuation
for the next steps of building a route.
-
buildStreaming
Description copied from interface:RouteStarter
Builds theStreamingHttpService
that performs the configured routing.- Specified by:
buildStreaming
in interfaceRouteStarter
- Returns:
- the router
StreamingHttpService
.
-