netflix.karyon.transport.http.HttpRequestHandlerBuilder Maven / Gradle / Ivy
package netflix.karyon.transport.http;
import io.netty.handler.codec.http.HttpMethod;
import io.reactivex.netty.protocol.http.server.HttpServerRequest;
import io.reactivex.netty.protocol.http.server.RequestHandler;
import netflix.karyon.transport.interceptor.InterceptorKey;
/**
* A convenience builder to create {@link HttpRequestHandler} instances.
*
* @author Nitesh Kant
*/
public class HttpRequestHandlerBuilder {
private final HttpInterceptorSupport interceptorSupport;
private final RequestHandler router;
public HttpRequestHandlerBuilder(RequestHandler router) {
this(new HttpInterceptorSupport(), router);
}
public HttpRequestHandlerBuilder(HttpInterceptorSupport interceptorSupport,
RequestHandler router) {
this.interceptorSupport = interceptorSupport;
this.router = router;
}
public HttpInterceptorSupport.HttpAttacher forKey(InterceptorKey, HttpKeyEvaluationContext> key) {
return interceptorSupport.forKey(key);
}
public HttpInterceptorSupport.HttpAttacher forUri(String uri) {
return interceptorSupport.forUri(uri);
}
public HttpInterceptorSupport.HttpAttacher forUriRegex(String uriRegEx) {
return interceptorSupport.forUriRegex(uriRegEx);
}
public HttpInterceptorSupport.HttpAttacher forHttpMethod(HttpMethod method) {
return interceptorSupport.forHttpMethod(method);
}
public HttpInterceptorSupport getInterceptorSupport() {
return interceptorSupport;
}
public RequestHandler getRouter() {
return router;
}
public HttpRequestHandler build() {
interceptorSupport.finish();
return new HttpRequestHandler(router, interceptorSupport);
}
}