use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class StaticPipelineBuilderTest method appliesPluginsInOrderTheyAreConfigured.
@Test
public void appliesPluginsInOrderTheyAreConfigured() throws Exception {
Iterable<NamedPlugin> plugins = List.of(interceptor("Test-A", appendResponseHeader("X-From-Plugin", "A")), interceptor("Test-B", appendResponseHeader("X-From-Plugin", "B")));
HttpHandler handler = new StaticPipelineFactory(clientFactory, environment, registry, plugins, executor, false).build();
LiveHttpResponse response = Mono.from(handler.handle(get("/foo").build(), requestContext())).block();
assertThat(response.status(), is(OK));
assertThat(response.headers("X-From-Plugin"), hasItems("B", "A"));
}
use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class StyxBackendServiceClientTest method removesBadContentLength.
@Test
public void removesBadContentLength() {
StyxHostHttpClient hostClient = mockHostClient(Flux.just(response(OK).addHeader(CONTENT_LENGTH, 50).addHeader(TRANSFER_ENCODING, CHUNKED).build()));
StyxBackendServiceClient styxHttpClient = new StyxBackendServiceClient.Builder(backendService.id()).metrics(metrics).loadBalancer(mockLoadBalancer(Optional.of(remoteHost(SOME_ORIGIN, toHandler(hostClient), hostClient)))).build();
LiveHttpResponse response = Mono.from(styxHttpClient.sendRequest(SOME_REQ, requestContext())).block();
assertThat(response.status(), is(OK));
assertThat(response.contentLength().isPresent(), is(false));
assertThat(response.header(TRANSFER_ENCODING).get(), is("chunked"));
}
use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class StyxBackendServiceClientTest method incrementsResponseStatusMetricsFor500.
@Test
public void incrementsResponseStatusMetricsFor500() {
StyxHostHttpClient hostClient = mockHostClient(Flux.just(response(INTERNAL_SERVER_ERROR).build()));
StyxBackendServiceClient styxHttpClient = new StyxBackendServiceClient.Builder(backendService.id()).metrics(metrics).loadBalancer(mockLoadBalancer(Optional.of(remoteHost(SOME_ORIGIN, toHandler(hostClient), hostClient)))).build();
LiveHttpResponse response = Mono.from(styxHttpClient.sendRequest(SOME_REQ, requestContext())).block();
assertThat(response.status(), is(INTERNAL_SERVER_ERROR));
verify(hostClient).sendRequest(eq(SOME_REQ), any(Context.class));
assertThat(meterRegistry.get("proxy.client.responseCode.errorStatus").tag("statusCode", "500").counter(), is(notNullValue()));
}
use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class StyxBackendServiceClientTest method prefersStickyOrigins.
@Test
public void prefersStickyOrigins() {
Origin origin = originWithId("localhost:234", "App-X", "Origin-Y");
StyxHostHttpClient hostClient = mockHostClient(Flux.just(response(OK).build()));
LoadBalancer loadBalancer = mockLoadBalancer(Optional.of(remoteHost(origin, toHandler(hostClient), hostClient)));
StyxBackendServiceClient styxHttpClient = new StyxBackendServiceClient.Builder(backendService.id()).loadBalancer(loadBalancer).metrics(metrics).build();
LiveHttpResponse response = Mono.from(styxHttpClient.sendRequest(get("/foo").cookies(requestCookie("styx_origin_" + Id.GENERIC_APP, "Origin-Y")).build(), requestContext())).block();
assertThat(response.status(), is(OK));
ArgumentCaptor<LoadBalancer.Preferences> argCaptor = ArgumentCaptor.forClass(LoadBalancer.Preferences.class);
verify(loadBalancer).choose(argCaptor.capture());
assertThat(argCaptor.getValue().preferredOrigins(), is(Optional.of("Origin-Y")));
}
use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class StyxBackendServiceClientTest method prefersRestrictedOrigins.
@Test
public void prefersRestrictedOrigins() {
Origin origin = originWithId("localhost:234", "App-X", "Origin-Y");
StyxHostHttpClient hostClient = mockHostClient(Flux.just(response(OK).build()));
LoadBalancer loadBalancer = mockLoadBalancer(Optional.of(remoteHost(origin, toHandler(hostClient), hostClient)));
StyxBackendServiceClient styxHttpClient = new StyxBackendServiceClient.Builder(backendService.id()).loadBalancer(loadBalancer).metrics(metrics).originsRestrictionCookieName("restrictedOrigin").build();
LiveHttpResponse response = Mono.from(styxHttpClient.sendRequest(get("/foo").cookies(requestCookie("restrictedOrigin", "Origin-Y")).build(), requestContext())).block();
assertThat(response.status(), is(OK));
ArgumentCaptor<LoadBalancer.Preferences> argCaptor = ArgumentCaptor.forClass(LoadBalancer.Preferences.class);
verify(loadBalancer).choose(argCaptor.capture());
assertThat(argCaptor.getValue().preferredOrigins(), is(Optional.of("Origin-Y")));
}
Aggregations