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"));
}
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));
}
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());
}
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());
}
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());
}
Aggregations