use of com.hotels.styx.api.LiveHttpResponse 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;
}
}
use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class ViaHeaderAppendingInterceptorTest method appendsHttp10RequestVersionInResponseViaHeader.
@Test
public void appendsHttp10RequestVersionInResponseViaHeader() throws Exception {
LiveHttpResponse response = Mono.from(interceptor.intercept(get("/foo").build(), ANY_RESPONSE_HANDLER)).block();
assertThat(response.headers().get(VIA), isValue("1.1 styx"));
}
use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class InstrumentedPluginTest method metricIsNotRecordedWhenErrorStatusIsReturnedByChain.
@Test
public void metricIsNotRecordedWhenErrorStatusIsReturnedByChain() {
Chain chain = request -> aResponse(INTERNAL_SERVER_ERROR);
String pluginName = "doNotRecordMe";
InstrumentedPlugin plugin = instrumentedPlugin(pluginName, PASS_THROUGH);
LiveHttpResponse response = Mono.from(plugin.intercept(someRequest, chain)).block();
assertThat(response.status(), is(INTERNAL_SERVER_ERROR));
assertThat(getStatusCount(pluginName, "500"), is(0.0));
assertThat(getErrorCount(pluginName), is(0.0));
}
use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class InstrumentedPluginTest method metricIsRecordedWhenResponseIsMappedToErrorStatus.
@Test
public void metricIsRecordedWhenResponseIsMappedToErrorStatus() {
Chain chain = request -> aResponse(OK);
String pluginName = "replaceStatus1";
InstrumentedPlugin plugin = instrumentedPlugin(pluginName, (request, aChain) -> aChain.proceed(request).map(response -> responseWithNewStatusCode(response, INTERNAL_SERVER_ERROR)));
LiveHttpResponse response = Mono.from(plugin.intercept(someRequest, chain)).block();
assertThat(response.status(), is(INTERNAL_SERVER_ERROR));
assertThat(getStatusCount(pluginName, "500"), is(1.0));
assertThat(getErrorCount(pluginName), is(1.0));
}
use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class InstrumentedPluginTest method errorsMetricIsNotRecordedWhenPluginReturnsNon5005xxStatusEarly.
@Test
public void errorsMetricIsNotRecordedWhenPluginReturnsNon5005xxStatusEarly() {
String pluginName = "returnEarly";
InstrumentedPlugin plugin = instrumentedPlugin(pluginName, (request, chain) -> aResponse(BAD_GATEWAY));
LiveHttpResponse response = Mono.from(plugin.intercept(someRequest, chain)).block();
verify(chain, never()).proceed(any(LiveHttpRequest.class));
assertThat(response.status(), is(BAD_GATEWAY));
assertThat(getStatusCount(pluginName, "502"), is(1.0));
assertThat(getErrorCount(pluginName), is(0.0));
}
Aggregations