use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class NettyToStyxRequestDecoderTest method completesContentObservableWhenLastHttpContentIsSeen.
@Test
public void completesContentObservableWhenLastHttpContentIsSeen() {
channel.writeInbound(chunkedRequestHeaders);
LiveHttpRequest request = (LiveHttpRequest) channel.readInbound();
TestSubscriber<?> contentSubscriber = subscribeTo(request.body());
assertThat(contentSubscriber.getOnCompletedEvents().size(), is(0));
channel.writeInbound(EMPTY_LAST_CONTENT);
assertThat(contentSubscriber.getOnCompletedEvents().size(), is(1));
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class NettyToStyxRequestDecoderTest method acceptsMalformedCookiesWithRelaxedValidation.
@Test
public void acceptsMalformedCookiesWithRelaxedValidation() {
HttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "http://foo.com/");
request.headers().set(HOST, "http://foo.com/");
request.headers().set("Cookie", "ABC01=\"1\"; ABC02=1; guid=a,b");
NettyToStyxRequestDecoder decoder = new NettyToStyxRequestDecoder.Builder().uniqueIdSupplier(uniqueIdSupplier).flowControlEnabled(true).build();
LiveHttpRequest styxRequest = decoder.makeAStyxRequestFrom(request, Observable.<ByteBuf>empty()).build();
LiveHttpRequest expected = new LiveHttpRequest.Builder(HttpMethod.GET, "http://foo.com/").cookies(requestCookie("ABC01", "\"1\""), requestCookie("ABC02", "1"), requestCookie("guid", "a,b")).build();
assertThat(new HashSet<>(styxRequest.cookies()), is(new HashSet<>(expected.cookies())));
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class HttpPipelineHandlerTest method closesTheConnectionAfterProxyingWhenConnectionHeaderHasValueClose.
@Test
public void closesTheConnectionAfterProxyingWhenConnectionHeaderHasValueClose() throws Exception {
LiveHttpRequest oneShotRequest = get("/closeAfterThis").header(CONNECTION, CLOSE).build();
handler.channelRead0(ctx, oneShotRequest);
assertThat(handler.state(), is(WAITING_FOR_RESPONSE));
verify(statsCollector).onRequest(oneShotRequest.id());
responseObservable.onNext(response);
responseObservable.onComplete();
assertThat(handler.state(), is(SENDING_RESPONSE));
writerFuture.complete(null);
assertThat(handler.state(), is(TERMINATED));
verify(statsCollector).onComplete(oneShotRequest.id(), response.status().code());
verify(ctx).close();
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class HttpPipelineHandlerTest method decrementsRequestsOngoingOnExceptionCaught.
@Test
public void decrementsRequestsOngoingOnExceptionCaught() throws Exception {
MeterRegistry registry = new MicrometerRegistry(new SimpleMeterRegistry());
HttpPipelineHandler adapter = handlerWithMocks(doNotRespondHandler).progressListener(new RequestStatsCollector(new CentralisedMetrics(registry))).build();
ChannelHandlerContext ctx = mockCtx();
adapter.channelActive(ctx);
LiveHttpRequest request = get("/foo").build();
adapter.channelRead0(ctx, request);
assertThat(requestOutstandingValue(registry), is(1.0));
adapter.exceptionCaught(ctx, new Throwable("Exception"));
assertThat(requestOutstandingValue(registry), is(0.0));
adapter.channelInactive(ctx);
assertThat(requestOutstandingValue(registry), is(0.0));
verify(responseEnhancer).enhance(any(LiveHttpResponse.Transformer.class), eq(request));
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class HttpMessageLoggingInterceptorTest method logsSecureRequests.
@Test
public void logsSecureRequests() {
LiveHttpRequest request = get("/").header("ReqHeader", "ReqHeaderValue").cookies(requestCookie("ReqCookie", "ReqCookieValue")).build();
consume(interceptor.intercept(request, chain(response(OK))));
assertThat(responseLogSupport.log(), contains(loggingEvent(INFO, "requestId=" + request.id() + ", secure=true, origin=null, request=" + FORMATTED_REQUEST), loggingEvent(INFO, "requestId=" + request.id() + ", secure=true, response=" + FORMATTED_RESPONSE)));
}
Aggregations