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