use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class InterceptorPipelineBuilderTest method buildsPipelineWithInterceptors.
@Test
public void buildsPipelineWithInterceptors() throws Exception {
HttpHandler pipeline = new InterceptorPipelineBuilder(environment, plugins, handler, false).build();
LiveHttpResponse response = Mono.from(pipeline.handle(get("/foo").build(), requestContext())).block();
assertThat(response.header("plug1"), isValue("1"));
assertThat(response.header("plug2"), isValue("1"));
assertThat(response.status(), is(OK));
}
use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class StandardHttpPipelineTest method passesThroughAllInterceptors.
@Test
public void passesThroughAllInterceptors() {
List<String> requestReceivers = new ArrayList<>();
List<String> responseReceivers = new ArrayList<>();
StandardHttpPipeline pipeline = pipeline(recordingInterceptor("interceptor 1", requestReceivers::add, responseReceivers::add), recordingInterceptor("interceptor 2", requestReceivers::add, responseReceivers::add), recordingInterceptor("interceptor 3", requestReceivers::add, responseReceivers::add));
LiveHttpResponse response = sendRequestTo(pipeline);
assertThat(response.status(), is(OK));
assertThat(requestReceivers, contains("interceptor 1", "interceptor 2", "interceptor 3"));
assertThat(responseReceivers, contains("interceptor 3", "interceptor 2", "interceptor 1"));
}
use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class StandardHttpPipelineTest method sendsExceptionUponExtraSubscriptionInsideInterceptor.
@ParameterizedTest
@MethodSource("multipleSubscriptionInterceptors")
public void sendsExceptionUponExtraSubscriptionInsideInterceptor(HttpInterceptor interceptor) throws Exception {
HttpHandler handler = (request, context) -> Eventual.of(response(OK).build());
List<HttpInterceptor> interceptors = singletonList(interceptor);
StandardHttpPipeline pipeline = new StandardHttpPipeline(interceptors, handler, RequestTracker.NO_OP);
Eventual<LiveHttpResponse> responseObservable = pipeline.handle(get("/").build(), requestContext());
assertThrows(IllegalStateException.class, () -> Mono.from(responseObservable).block());
}
use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class StandardHttpPipelineTest method sendsExceptionUponMultipleSubscription.
@Test
public void sendsExceptionUponMultipleSubscription() {
HttpHandler handler = (request, context) -> Eventual.of(response(OK).build());
StandardHttpPipeline pipeline = new StandardHttpPipeline(handler);
Eventual<LiveHttpResponse> responseObservable = pipeline.handle(get("/").build(), requestContext());
LiveHttpResponse response = Mono.from(responseObservable).block();
assertThat(response.status(), is(OK));
assertThrows(IllegalStateException.class, () -> Mono.from(responseObservable).block());
}
use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class HttpPipelineHandler method onResponseObservableError.
private State onResponseObservableError(ChannelHandlerContext ctx, Throwable cause, Object requestId) {
if (!ongoingRequest.id().equals(requestId)) {
return this.state();
}
metrics.proxy().server().requestsCancelled("responseError").increment();
cancelSubscription();
LOGGER.error(warningMessage(format("message='Error proxying request', requestId=%s cause=%s", requestId, cause)));
if (cause instanceof ConsumerDisconnectedException) {
return TERMINATED;
}
LiveHttpResponse response = exceptionToResponse(cause, ongoingRequest, originsHeaderName);
responseWriterFactory.create(ctx).write(response).handle((ignore, exception) -> {
if (exception != null) {
httpErrorStatusListener.proxyErrorOccurred(cause);
httpErrorStatusListener.proxyErrorOccurred(exception);
} else {
httpErrorStatusListener.proxyErrorOccurred(ongoingRequest, remoteAddress(ctx), response.status(), cause);
statsSink.onComplete(ongoingRequest.id(), response.status().code());
tracker.endTrack(ongoingRequest);
}
ctx.close();
return null;
}).handle((ignore, exception) -> {
statsSink.onTerminate(ongoingRequest.id());
tracker.endTrack(ongoingRequest);
if (exception != null) {
LOGGER.error(warningMessage("message='Error during write completion handling'"), exception);
}
return null;
});
return TERMINATED;
}
Aggregations