Search in sources :

Example 6 with LiveHttpRequest

use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.

the class NettyToStyxRequestDecoderTest method overridesTheHostHeaderWithTheHostAndPortInTheAbsoluteURI.

@Test
public void overridesTheHostHeaderWithTheHostAndPortInTheAbsoluteURI() {
    HttpRequest request = newHttpRequest(URI.create("http://example.net/foo").toString());
    request.headers().set(HOST, "www.example.com:8000");
    LiveHttpRequest styxRequest = decode(request);
    assertThat(styxRequest.headers().get(HOST).get(), is("example.net"));
}
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) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 7 with LiveHttpRequest

use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.

the class NettyToStyxRequestDecoderTest method canHandleNettyCookies.

@Test
public void canHandleNettyCookies() {
    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=xxxxx-xxx-xxx-xxx-xxxxxxx");
    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", "xxxxx-xxx-xxx-xxx-xxxxxxx")).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 8 with LiveHttpRequest

use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.

the class HttpPipelineHandlerTest method cancelsOngoingRequestWhenSpuriousRequestArrivesInWaitingForResponseState.

@Test
public void cancelsOngoingRequestWhenSpuriousRequestArrivesInWaitingForResponseState() throws Exception {
    // - writes EMPTY_LAST_CONTENT and closes the channel
    // - logs an error message
    // - cancels the ongoing request on the HTTP pipeline
    LiveHttpRequest spurious = get("/bar").build();
    setupHandlerTo(WAITING_FOR_RESPONSE);
    handler.channelRead0(ctx, spurious);
    verify(statsCollector).onTerminate(request.id());
    assertThat(handler.state(), is(TERMINATED));
    assertThat(logger.lastMessage(), is(loggingEvent(WARN, "message='Spurious request received while handling another request'.*")));
    assertThat(responseUnsubscribed.get(), is(true));
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 9 with LiveHttpRequest

use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.

the class AntlrConditionTest method notExpressionNegatesTheExpressionResult.

@Test
public void notExpressionNegatesTheExpressionResult() {
    Condition condition = condition("NOT header('Host')");
    LiveHttpRequest request1 = newRequest().header(HOST, "bbc.co.uk").build();
    assertThat(condition.evaluate(request1, context), is(false));
    LiveHttpRequest request2 = newRequest().header(CONTENT_LENGTH, 7).build();
    assertThat(condition.evaluate(request2, context), is(true));
}
Also used : Condition(com.hotels.styx.server.routing.Condition) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 10 with LiveHttpRequest

use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.

the class AntlrConditionTest method notExpressionHasHigherPrecedenceThanAndExpression.

@Test
public void notExpressionHasHigherPrecedenceThanAndExpression() {
    Condition condition = condition("header('Host') " + "AND NOT header('App-Name') =~ 'app[0-9]' OR header('App-Name') =~ 'shop[0-9]'");
    LiveHttpRequest request1 = newRequest().header(HOST, "bbc.co.uk").header("App-Name", "landing1").build();
    assertThat(condition.evaluate(request1, context), is(true));
    LiveHttpRequest request2 = newRequest().header(HOST, "bbc.co.uk").header("App-Name", "app2").build();
    assertThat(condition.evaluate(request2, context), is(false));
    LiveHttpRequest request3 = newRequest().header(HOST, "bbc.co.uk").header("App-Name", "shop1").build();
    assertThat(condition.evaluate(request3, context), is(true));
}
Also used : Condition(com.hotels.styx.server.routing.Condition) 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