Search in sources :

Example 56 with LiveHttpRequest

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

the class StyxBackendServiceClientFactoryTest method usesTheOriginSpecifiedInTheStickySessionCookie.

@Test
public void usesTheOriginSpecifiedInTheStickySessionCookie() {
    BackendService backendService = newBackendServiceBuilder().origins(newOriginBuilder("localhost", 9091).id("x").build(), newOriginBuilder("localhost", 9092).id("y").build(), newOriginBuilder("localhost", 9093).id("z").build()).stickySessionConfig(newStickySessionConfigBuilder().enabled(true).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(STICKY_COOKIE, id("z").toString())).build();
    LiveHttpRequest requestx = get("/some-req").cookies(requestCookie(STICKY_COOKIE, id("x").toString())).build();
    LiveHttpRequest requesty = get("/some-req").cookies(requestCookie(STICKY_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) 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) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Example 57 with LiveHttpRequest

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

the class ConfigurationContextResolverInterceptorTest method resolvesConfigurationContext.

@Test
public void resolvesConfigurationContext() {
    LiveHttpRequest request = get("/").build();
    Configuration.Context context = context(Map.of("key1", "value1", "key2", "value2"));
    ConfigurationContextResolver configurationContextResolver = configurationContextResolver(request, context);
    ConfigurationContextResolverInterceptor interceptor = new ConfigurationContextResolverInterceptor(configurationContextResolver);
    TestChain chain = new TestChain();
    Eventual<LiveHttpResponse> responseObservable = interceptor.intercept(request, chain);
    assertThat(Mono.from(responseObservable).block(), hasStatus(OK));
    assertThat(chain.proceedWasCalled, is(true));
    assertThat(chain.context().get("config.context", Configuration.Context.class), is(context));
}
Also used : ConfigurationContextResolver(com.hotels.styx.api.configuration.ConfigurationContextResolver) Support.requestContext(com.hotels.styx.support.Support.requestContext) Configuration(com.hotels.styx.api.configuration.Configuration) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Example 58 with LiveHttpRequest

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

the class HopByHopHeadersRemovingInterceptorTest method removesConnectionHeaders.

@Test
public void removesConnectionHeaders() {
    LiveHttpRequest request = post("/foo").header(CONNECTION, "Foo, Bar, Baz").header("Foo", "abc").header("Foo", "def").header("Bar", "one, two, three").build();
    LiveHttpRequest interceptedRequest = interceptRequest(request);
    assertThat(interceptedRequest.header(CONNECTION), isAbsent());
    assertThat(interceptedRequest.header("Foo"), isAbsent());
    assertThat(interceptedRequest.header("Bar"), isAbsent());
    assertThat(interceptedRequest.header("Baz"), isAbsent());
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 59 with LiveHttpRequest

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

the class HopByHopHeadersRemovingInterceptorTest method removesConnectionHeaderContainingOneTokenOnly.

@Test
public void removesConnectionHeaderContainingOneTokenOnly() {
    LiveHttpRequest request = delete("/foo").header(CONNECTION, "Foo").header("Foo", "abc").build();
    LiveHttpRequest interceptedRequest = interceptRequest(request);
    assertThat(interceptedRequest.header(CONNECTION), isAbsent());
    assertThat(interceptedRequest.header("Foo"), isAbsent());
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 60 with LiveHttpRequest

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

the class HopByHopHeadersRemovingInterceptorTest method removesHopByHopHeadersFromRequest.

@Test
public void removesHopByHopHeadersFromRequest() {
    LiveHttpRequest request = get("/foo").header(TE, "Foo").header(PROXY_AUTHENTICATE, "foo").header(PROXY_AUTHORIZATION, "bar").build();
    LiveHttpRequest interceptedRequest = interceptRequest(request);
    assertThat(interceptedRequest.header(TE), isAbsent());
    assertThat(interceptedRequest.header(PROXY_AUTHENTICATE), isAbsent());
    assertThat(interceptedRequest.header(PROXY_AUTHORIZATION), isAbsent());
}
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