Search in sources :

Example 1 with LiveHttpRequest

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

the class TestPlugin method intercept.

@Override
public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain chain) {
    String header = xHcomPluginsHeader(request);
    LiveHttpRequest newRequest = request.newBuilder().header(X_HCOM_PLUGINS_HEADER, header).header("X-Hcom-Styx-Started", styxStarted).header("X-Hcom-Styx-Stopped", styxStopped).build();
    Function<ByteBuf, String> byteBufStringFunction = byteBuf -> byteBuf.toString(UTF_8);
    return chain.proceed(newRequest).flatMap(response -> response.aggregate(1 * 1024 * 1024)).map(response -> response.newBuilder().header(X_HCOM_PLUGINS_HEADER, header).header("X-Hcom-Styx-Started", styxStarted).header("X-Hcom-Styx-Stopped", styxStopped).addHeader("X-Plugin-Identifier", config.getId()).build()).map(HttpResponse::stream);
}
Also used : Eventual(com.hotels.styx.api.Eventual) HttpResponse(com.hotels.styx.api.HttpResponse) HttpHandler(com.hotels.styx.api.HttpHandler) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) ByteBuf(io.netty.buffer.ByteBuf) Plugin(com.hotels.styx.api.plugins.spi.Plugin) PluginFactory(com.hotels.styx.api.plugins.spi.PluginFactory) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Map(java.util.Map) Collections(java.util.Collections) Function(java.util.function.Function) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) HttpResponse(com.hotels.styx.api.HttpResponse) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) ByteBuf(io.netty.buffer.ByteBuf)

Example 2 with LiveHttpRequest

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

the class NettyToStyxRequestDecoderTest method decodesNettyInternalRequestToStyxRequest.

@Test
public void decodesNettyInternalRequestToStyxRequest() throws Exception {
    FullHttpRequest originalRequest = newHttpRequest("/uri");
    HttpHeaders originalRequestHeaders = originalRequest.headers();
    originalRequestHeaders.add("Foo", "Bar");
    originalRequestHeaders.add("Bar", "Bar");
    originalRequestHeaders.add("Host", "foo.com");
    LiveHttpRequest styxRequest = decode(originalRequest);
    assertThat(styxRequest.id().toString(), is("1"));
    assertThat(styxRequest.url().encodedUrl(), is(originalRequest.getUri()));
    assertThat(styxRequest.method(), is(HttpMethod.GET));
    assertThatHttpHeadersAreSame(styxRequest.headers(), originalRequestHeaders);
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 3 with LiveHttpRequest

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

the class NettyToStyxRequestDecoderTest method buffersIncomingDataUntilSubscriberHasSubscribed.

@Test
public void buffersIncomingDataUntilSubscriberHasSubscribed() throws Exception {
    channel.writeInbound(chunkedRequestHeaders);
    LiveHttpRequest request = (LiveHttpRequest) channel.readInbound();
    channel.writeInbound(contentChunkOne);
    channel.writeInbound(contentChunkTwo);
    channel.writeInbound(contentChunkThree);
    String content = subscribeAndRead(request.body());
    assertThat(content, is("content chunk 1 content chunk 2 content chunk 3"));
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 4 with LiveHttpRequest

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

the class NettyToStyxRequestDecoderTest method removesExpectHeaderBeforePassingThroughTheRequest.

@Test
public void removesExpectHeaderBeforePassingThroughTheRequest() throws Exception {
    FullHttpRequest originalRequest = newHttpRequest("/uri");
    originalRequest.headers().set(EXPECT, CONTINUE);
    originalRequest.headers().set(HOST, "foo.com");
    LiveHttpRequest styxRequest = decode(originalRequest);
    assertThat(styxRequest.header(EXPECT).isPresent(), is(false));
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 5 with LiveHttpRequest

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

the class NettyToStyxRequestDecoderTest method streamsIncomingHttpContentToTheContentSubscriber.

@Test
public void streamsIncomingHttpContentToTheContentSubscriber() throws Exception {
    channel.writeInbound(chunkedRequestHeaders);
    LiveHttpRequest request = (LiveHttpRequest) channel.readInbound();
    StringBuilder content = subscribeToContent(request.body(), bodyCompletedLatch);
    channel.writeInbound(contentChunkOne);
    channel.writeInbound(contentChunkTwo);
    channel.writeInbound(contentChunkThree);
    bodyCompletedLatch.await();
    assertThat(content.toString(), is("content chunk 1 content chunk 2 content chunk 3"));
}
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