Search in sources :

Example 66 with LiveHttpRequest

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));
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 67 with LiveHttpRequest

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())));
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) ByteBuf(io.netty.buffer.ByteBuf) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 68 with LiveHttpRequest

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();
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 69 with LiveHttpRequest

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));
}
Also used : RequestStatsCollector(com.hotels.styx.server.RequestStatsCollector) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(com.hotels.styx.api.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 70 with LiveHttpRequest

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)));
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Aggregations

LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)82 Test (org.junit.jupiter.api.Test)76 Condition (com.hotels.styx.server.routing.Condition)19 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)14 HttpHandler (com.hotels.styx.api.HttpHandler)10 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)9 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)9 MeterRegistry (com.hotels.styx.api.MeterRegistry)8 BackendService (com.hotels.styx.api.extension.service.BackendService)7 Registry (com.hotels.styx.api.extension.service.spi.Registry)7 Eventual (com.hotels.styx.api.Eventual)6 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)6 HttpResponse (com.hotels.styx.api.HttpResponse)5 Origin.newOriginBuilder (com.hotels.styx.api.extension.Origin.newOriginBuilder)5 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)5 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 Mono (reactor.core.publisher.Mono)5 HttpRequestMessageLogger (com.hotels.styx.common.logging.HttpRequestMessageLogger)4 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)4