use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class ViaHeaderAppendingInterceptorTest method appendsViaHeaderValueAtEndOfListInResponse.
@Test
public void appendsViaHeaderValueAtEndOfListInResponse() throws Exception {
LiveHttpResponse response = Mono.from(interceptor.intercept(get("/foo").build(), returnsResponse(response().header(VIA, "1.0 ricky, 1.1 mertz, 1.0 lucy").build()))).block();
assertThat(response.headers().get(VIA), isValue("1.0 ricky, 1.1 mertz, 1.0 lucy, 1.1 styx"));
}
use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class InstrumentedPluginTest method metricIsRecordedWhenPluginReturnsErrorStatusEarly.
@Test
public void metricIsRecordedWhenPluginReturnsErrorStatusEarly() {
String pluginName = "returnEarly1";
InstrumentedPlugin plugin = instrumentedPlugin(pluginName, (request, chain) -> aResponse(INTERNAL_SERVER_ERROR));
LiveHttpResponse response = Mono.from(plugin.intercept(someRequest, chain)).block();
verify(chain, never()).proceed(any(LiveHttpRequest.class));
assertThat(response.status(), is(INTERNAL_SERVER_ERROR));
assertThat(getStatusCount(pluginName, "500"), is(1.0));
assertThat(getErrorCount(pluginName), is(1.0));
}
use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class InstrumentedPluginTest method errorsMetricIsNotRecordedWhenResponseIsMappedToNon5005xxStatus.
@Test
public void errorsMetricIsNotRecordedWhenResponseIsMappedToNon5005xxStatus() {
Chain chain = request -> aResponse(OK);
String pluginName = "replaceStatusCodeY";
InstrumentedPlugin plugin = instrumentedPlugin("replaceStatusCodeY", (request, aChain) -> aChain.proceed(request).map(response -> responseWithNewStatusCode(response, BAD_GATEWAY)));
LiveHttpResponse response = Mono.from(plugin.intercept(someRequest, chain)).block();
assertThat(response.status(), is(BAD_GATEWAY));
assertThat(getStatusCount(pluginName, "502"), is(1.0));
assertThat(getErrorCount(pluginName), is(0.0));
}
use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class StaticPipelineBuilderTest method buildsInterceptorPipelineForBackendServices.
@Test
public void buildsInterceptorPipelineForBackendServices() throws Exception {
HttpHandler handler = new StaticPipelineFactory(clientFactory, environment, registry, List.of(), executor, false).build();
LiveHttpResponse response = Mono.from(handler.handle(get("/foo").build(), requestContext())).block();
assertThat(response.status(), is(OK));
}
use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.
the class StyxToNettyResponseTranslatorTest method shouldCreateNettyResponseWithCookieWithAttributes.
@Test
public void shouldCreateNettyResponseWithCookieWithAttributes() {
ResponseCookie cookie = responseCookie("cookie-test", "cookie-value").domain("cookie-domain").path("cookie-path").maxAge(1234).httpOnly(true).secure(true).build();
LiveHttpResponse styxResponse = new LiveHttpResponse.Builder(OK).cookies(cookie).build();
io.netty.handler.codec.http.HttpResponse nettyResponse = translator.toNettyResponse(styxResponse);
String setCookie = nettyResponse.headers().get(SET_COOKIE);
Cookie nettyCookie = ClientCookieDecoder.LAX.decode(setCookie);
assertThat(nettyCookie.name(), is("cookie-test"));
assertThat(nettyCookie.value(), is("cookie-value"));
assertThat(nettyCookie.domain(), is("cookie-domain"));
assertThat(nettyCookie.maxAge(), is(1234L));
assertThat(nettyCookie.isHttpOnly(), is(true));
assertThat(nettyCookie.isSecure(), is(true));
}
Aggregations