Search in sources :

Example 76 with LiveHttpResponse

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"));
}
Also used : LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Example 77 with LiveHttpResponse

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));
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Example 78 with LiveHttpResponse

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));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) StepVerifier(reactor.test.StepVerifier) LiveHttpResponse.response(com.hotels.styx.api.LiveHttpResponse.response) Eventual.error(com.hotels.styx.api.Eventual.error) Matchers.not(org.hamcrest.Matchers.not) PluginException(com.hotels.styx.api.plugins.spi.PluginException) LiveHttpRequest.get(com.hotels.styx.api.LiveHttpRequest.get) NamedPlugin.namedPlugin(com.hotels.styx.proxy.plugin.NamedPlugin.namedPlugin) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) PASS_THROUGH(com.hotels.styx.api.plugins.spi.Plugin.PASS_THROUGH) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Counter(io.micrometer.core.instrument.Counter) Eventual(com.hotels.styx.api.Eventual) INTERNAL_SERVER_ERROR(com.hotels.styx.api.HttpResponseStatus.INTERNAL_SERVER_ERROR) Plugin(com.hotels.styx.api.plugins.spi.Plugin) Mono(reactor.core.publisher.Mono) HttpResponseStatus(com.hotels.styx.api.HttpResponseStatus) Metrics.formattedExceptionName(com.hotels.styx.api.Metrics.formattedExceptionName) Chain(com.hotels.styx.api.HttpInterceptor.Chain) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) Mockito.never(org.mockito.Mockito.never) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) MeterRegistry(com.hotels.styx.api.MeterRegistry) Environment(com.hotels.styx.Environment) OK(com.hotels.styx.api.HttpResponseStatus.OK) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) BAD_GATEWAY(com.hotels.styx.api.HttpResponseStatus.BAD_GATEWAY) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Mockito.mock(org.mockito.Mockito.mock) Chain(com.hotels.styx.api.HttpInterceptor.Chain) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Example 79 with LiveHttpResponse

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));
}
Also used : HttpHandler(com.hotels.styx.api.HttpHandler) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Example 80 with LiveHttpResponse

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));
}
Also used : Cookie(io.netty.handler.codec.http.cookie.Cookie) ResponseCookie(com.hotels.styx.api.ResponseCookie) ResponseCookie.responseCookie(com.hotels.styx.api.ResponseCookie.responseCookie) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) ResponseCookie(com.hotels.styx.api.ResponseCookie) 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