netflix.karyon.transport.http.HttpRequestHandler Maven / Gradle / Ivy
package netflix.karyon.transport.http;
import io.reactivex.netty.protocol.http.server.HttpServerRequest;
import io.reactivex.netty.protocol.http.server.HttpServerResponse;
import io.reactivex.netty.protocol.http.server.RequestHandler;
import netflix.karyon.transport.interceptor.AbstractInterceptorSupport;
import netflix.karyon.transport.interceptor.InterceptorExecutor;
import rx.Observable;
/**
* An implementation of {@link RequestHandler} for karyon.
*
* @author Nitesh Kant
*/
public class HttpRequestHandler implements RequestHandler {
private final InterceptorExecutor, HttpServerResponse, HttpKeyEvaluationContext> executor;
public HttpRequestHandler(RequestHandler router) {
this(router, new HttpInterceptorSupport());
}
public HttpRequestHandler(RequestHandler router,
AbstractInterceptorSupport, HttpServerResponse, HttpKeyEvaluationContext, ?, ?> interceptorSupport) {
executor = new InterceptorExecutor, HttpServerResponse, HttpKeyEvaluationContext>(interceptorSupport, router);
}
@Override
public Observable handle(HttpServerRequest request, HttpServerResponse response) {
return executor.execute(request, response, new HttpKeyEvaluationContext(response.getChannel()));
}
}