Search in sources :

Example 31 with LiveHttpResponse

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

the class HttpRequestMessageLoggerTest method logsClientSideResponseDetailsShortFormat.

@Test
public void logsClientSideResponseDetailsShortFormat() {
    LiveHttpRequest styxRequest = get("http://www.hotels.com/foo/bar/request").build();
    LiveHttpResponse styxResponse = response(OK).build();
    new HttpRequestMessageLogger("com.hotels.styx.http-messages.outbound", false, httpMessageFormatter).logResponse(styxRequest, styxResponse);
    assertThat(log.lastMessage(), is(loggingEvent(INFO, format("requestId=%s, response=\\{version=HTTP/1.1, status=200 OK\\}", styxRequest.id()))));
}
Also used : HttpRequestMessageLogger(com.hotels.styx.common.logging.HttpRequestMessageLogger) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 32 with LiveHttpResponse

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

the class NettyToStyxResponsePropagatorTest method completesContentObservableOnLastHttpContent.

@Test
public void completesContentObservableOnLastHttpContent() throws Exception {
    EmbeddedChannel channel = new EmbeddedChannel(new NettyToStyxResponsePropagator(responseSubscriber, SOME_ORIGIN));
    channel.writeInbound(httpResponseHeaders);
    channel.writeInbound(EMPTY_LAST_CONTENT);
    LiveHttpResponse response = verifyNextCalledOnResponseSubscriber();
    StepVerifier.create(response.body()).then(channel::runPendingTasks).verifyComplete();
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Example 33 with LiveHttpResponse

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

the class NettyToStyxResponsePropagatorTest method handlesIdleStateEvent.

@Test
public void handlesIdleStateEvent() throws Exception {
    EmbeddedChannel channel = new EmbeddedChannel(new NettyToStyxResponsePropagator(responseSubscriber, SOME_ORIGIN));
    channel.writeInbound(httpResponseHeaders);
    LiveHttpResponse response = verifyNextCalledOnResponseSubscriber();
    StepVerifier.create(response.body()).then(// Execute onSubscribe in FSM
    channel::runPendingTasks).then(() -> channel.pipeline().fireUserEventTriggered(ALL_IDLE_STATE_EVENT)).expectError(ResponseTimeoutException.class).verify();
}
Also used : ResponseTimeoutException(com.hotels.styx.api.exceptions.ResponseTimeoutException) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Example 34 with LiveHttpResponse

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

the class StyxBackendServiceClientFactoryTest method usesTheOriginSpecifiedInTheOriginsRestrictionCookie.

@Test
public void usesTheOriginSpecifiedInTheOriginsRestrictionCookie() {
    MapBackedConfiguration config = new MapBackedConfiguration();
    config.set("originRestrictionCookie", ORIGINS_RESTRICTION_COOKIE);
    environment = new Environment.Builder().registry(new MicrometerRegistry(new SimpleMeterRegistry())).configuration(new StyxConfig(config)).build();
    BackendService backendService = newBackendServiceBuilder().origins(newOriginBuilder("localhost", 9091).id("x").build(), newOriginBuilder("localhost", 9092).id("y").build(), newOriginBuilder("localhost", 9093).id("z").build()).build();
    BackendServiceClient styxBackendServiceClient = new StyxBackendServiceClientFactory(environment).createClient(backendService, newOriginsInventoryBuilder(environment.centralisedMetrics(), backendService).hostClientFactory((pool) -> {
        if (pool.getOrigin().id().equals(id("x"))) {
            return hostClient(response(OK).header("X-Origin-Id", "x").build());
        } else if (pool.getOrigin().id().equals(id("y"))) {
            return hostClient(response(OK).header("X-Origin-Id", "y").build());
        } else {
            return hostClient(response(OK).header("X-Origin-Id", "z").build());
        }
    }).build(), new CachingOriginStatsFactory(environment.centralisedMetrics()));
    LiveHttpRequest requestz = get("/some-req").cookies(requestCookie(ORIGINS_RESTRICTION_COOKIE, id("z").toString())).build();
    LiveHttpRequest requestx = get("/some-req").cookies(requestCookie(ORIGINS_RESTRICTION_COOKIE, id("x").toString())).build();
    LiveHttpRequest requesty = get("/some-req").cookies(requestCookie(ORIGINS_RESTRICTION_COOKIE, id("y").toString())).build();
    LiveHttpResponse responsez = Mono.from(styxBackendServiceClient.sendRequest(requestz, requestContext())).block();
    LiveHttpResponse responsex = Mono.from(styxBackendServiceClient.sendRequest(requestx, requestContext())).block();
    LiveHttpResponse responsey = Mono.from(styxBackendServiceClient.sendRequest(requesty, requestContext())).block();
    assertThat(responsex.header("X-Origin-Id").get(), is("x"));
    assertThat(responsey.header("X-Origin-Id").get(), is("y"));
    assertThat(responsez.header("X-Origin-Id").get(), is("z"));
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) StyxConfig(com.hotels.styx.StyxConfig) StyxBackendServiceClient(com.hotels.styx.client.StyxBackendServiceClient) BackendServiceClient(com.hotels.styx.client.BackendServiceClient) CachingOriginStatsFactory(com.hotels.styx.client.OriginStatsFactory.CachingOriginStatsFactory) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) OriginsInventory.newOriginsInventoryBuilder(com.hotels.styx.client.OriginsInventory.newOriginsInventoryBuilder) Origin.newOriginBuilder(com.hotels.styx.api.extension.Origin.newOriginBuilder) BackendService.newBackendServiceBuilder(com.hotels.styx.api.extension.service.BackendService.newBackendServiceBuilder) StickySessionConfig.newStickySessionConfigBuilder(com.hotels.styx.api.extension.service.StickySessionConfig.newStickySessionConfigBuilder) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MapBackedConfiguration(com.hotels.styx.api.configuration.Configuration.MapBackedConfiguration) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Example 35 with LiveHttpResponse

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

the class HopByHopHeadersRemovingInterceptorTest method removesHopByHopHeadersFromResponse.

@Test
public void removesHopByHopHeadersFromResponse() throws Exception {
    LiveHttpResponse response = Mono.from(interceptor.intercept(get("/foo").build(), returnsResponse(response().header(TE, "foo").header(PROXY_AUTHENTICATE, "foo").header(PROXY_AUTHORIZATION, "bar").build()))).block();
    assertThat(response.header(TE), isAbsent());
    assertThat(response.header(PROXY_AUTHENTICATE), isAbsent());
    assertThat(response.header(PROXY_AUTHORIZATION), isAbsent());
}
Also used : LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)80 Test (org.junit.jupiter.api.Test)69 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)25 Support.requestContext (com.hotels.styx.support.Support.requestContext)21 Eventual (com.hotels.styx.api.Eventual)15 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)15 HttpHandler (com.hotels.styx.api.HttpHandler)14 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)14 Mono (reactor.core.publisher.Mono)14 ByteStream (com.hotels.styx.api.ByteStream)13 Context (com.hotels.styx.api.HttpInterceptor.Context)13 OK (com.hotels.styx.api.HttpResponseStatus.OK)13 LiveHttpResponse.response (com.hotels.styx.api.LiveHttpResponse.response)13 TransportLostException (com.hotels.styx.api.exceptions.TransportLostException)12 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)12 CompletableFuture (java.util.concurrent.CompletableFuture)12 Matchers.is (org.hamcrest.Matchers.is)12 Buffer (com.hotels.styx.api.Buffer)11 LiveHttpRequest.get (com.hotels.styx.api.LiveHttpRequest.get)11 HttpInterceptorContext (com.hotels.styx.server.HttpInterceptorContext)11