Search in sources :

Example 1 with HttpInterceptorContext

use of com.hotels.styx.server.HttpInterceptorContext in project styx by ExpediaGroup.

the class HttpPipelineHandler method onLegitimateRequest.

private State onLegitimateRequest(LiveHttpRequest request, ChannelHandlerContext ctx) {
    statsSink.onRequest(request.id());
    LiveHttpRequest v11Request = request.newBuilder().version(HTTP_1_1).build();
    tracker.trackRequest(request, () -> this.state().toString());
    ongoingRequest = request;
    // generates a response.
    try {
        Eventual<LiveHttpResponse> responseEventual = httpPipeline.handle(v11Request, new HttpInterceptorContext(this.secure, remoteAddress(ctx), ctx.executor()));
        responseEventual.subscribe(new BaseSubscriber<LiveHttpResponse>() {

            @Override
            public void hookOnSubscribe(Subscription s) {
                subscription = s;
                s.request(1);
            }

            @Override
            public void hookOnComplete() {
                eventProcessor.submit(new ResponseObservableCompletedEvent(ctx, request.id()));
            }

            @Override
            public void hookOnError(Throwable cause) {
                eventProcessor.submit(new ResponseObservableErrorEvent(ctx, cause, request.id()));
            }

            @Override
            public void hookOnNext(LiveHttpResponse response) {
                eventProcessor.submit(new ResponseReceivedEvent(response, ctx));
            }
        });
        return WAITING_FOR_RESPONSE;
    } catch (Throwable cause) {
        LiveHttpResponse response = exceptionToResponse(cause, request, originsHeaderName);
        httpErrorStatusListener.proxyErrorOccurred(request, remoteAddress(ctx), response.status(), cause);
        statsSink.onTerminate(request.id());
        tracker.endTrack(ongoingRequest);
        if (ctx.channel().isActive()) {
            respondAndClose(ctx, response);
        }
        return TERMINATED;
    }
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) HttpInterceptorContext(com.hotels.styx.server.HttpInterceptorContext) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Subscription(org.reactivestreams.Subscription)

Aggregations

LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)1 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)1 HttpInterceptorContext (com.hotels.styx.server.HttpInterceptorContext)1 Subscription (org.reactivestreams.Subscription)1