use of com.hotels.styx.api.HttpResponseStatus.OK in project styx by ExpediaGroup.
the class HttpAggregatorTest method aggregatesRequestAndStreamsResponses.
@Test
public void aggregatesRequestAndStreamsResponses() {
AtomicReference<String> result = new AtomicReference<>();
WebServiceHandler webServiceHandler = (request, ctx) -> {
result.set(request.bodyAs(UTF_8));
return Eventual.of(response(OK).body("abcdef", UTF_8).build());
};
LiveHttpResponse response = Mono.from(new HttpAggregator(500, webServiceHandler).handle(LiveHttpRequest.post("/").body(ByteStream.from("ABCDEF", UTF_8)).build(), requestContext())).block();
assertThat(result.get(), is("ABCDEF"));
assertThat(Mono.from(response.aggregate(500)).block().bodyAs(UTF_8), is("abcdef"));
}
use of com.hotels.styx.api.HttpResponseStatus.OK in project styx by ExpediaGroup.
the class HttpStreamerTest method streamsRequestAndAggregatesResponses.
@Test
public void streamsRequestAndAggregatesResponses() {
HttpHandler httpHandler = (request, ctx) -> Eventual.of(LiveHttpResponse.response(OK).body(ByteStream.from("abcdef", UTF_8)).build());
HttpResponse response = Mono.from(new HttpStreamer(500, httpHandler).handle(HttpRequest.post("/").body("ABCDEF", UTF_8).build(), requestContext())).block();
assertThat(response.bodyAs(UTF_8), is("abcdef"));
}
use of com.hotels.styx.api.HttpResponseStatus.OK in project styx by ExpediaGroup.
the class HttpResponseWriterTest method releasesContentChunksWhenFailsToConvertToNettyHeaders.
@Test
public void releasesContentChunksWhenFailsToConvertToNettyHeaders() throws Exception {
CaptureHttpResponseWriteEventsHandler writeEventsCollector = new CaptureHttpResponseWriteEventsHandler();
Buffer chunk1 = new Buffer("aaa", UTF_8);
Buffer chunk2 = new Buffer("aaa", UTF_8);
AtomicBoolean unsubscribed = new AtomicBoolean(false);
EmbeddedChannel ch = new EmbeddedChannel(new CaptureChannelArgumentsHandler(channelArgs), writeEventsCollector, new SimpleChannelInboundHandler<LiveHttpResponse>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, LiveHttpResponse response) throws Exception {
HttpResponseWriter writer = new HttpResponseWriter(ctx, httpResponse -> {
throw new RuntimeException();
});
CompletableFuture<Void> future = writer.write(response);
contentObservable.onNext(chunk1);
contentObservable.onNext(chunk2);
contentObservable.onComplete();
assertThat(future.isDone(), is(true));
assertThat(toByteBuf(chunk1).refCnt(), is(0));
assertThat(toByteBuf(chunk2).refCnt(), is(0));
channelRead.set(true);
}
});
LiveHttpResponse.Builder response = response(OK).cookies(responseCookie(",,,,", ",,,,").build());
ch.writeInbound(response.body(new ByteStream(contentObservable.doOnCancel(() -> unsubscribed.set(true)))).build());
assertThat(channelRead.get(), is(true));
}
use of com.hotels.styx.api.HttpResponseStatus.OK in project styx by ExpediaGroup.
the class StyxServerTest method executesPluginsWhenProxying.
@Test
public void executesPluginsWhenProxying() {
Plugin responseDecorator = (request, chain) -> chain.proceed(request).map(response -> response.newBuilder().header("plugin-executed", "yes").build());
PluginFactory pluginFactory = environment -> responseDecorator;
styxServer = new StyxServer.Builder().addRoute("/", originServer1.port()).addPluginFactory("response-decorator", pluginFactory, null).start();
HttpResponse response = await(client.sendRequest(get(format("http://localhost:%d/foo", styxServer.proxyHttpPort())).build()));
assertThat(response.status(), is(OK));
assertThat(response.header("origin"), isValue("first"));
assertThat(response.header("plugin-executed"), isValue("yes"));
configureFor(originServer1.port());
WireMock.verify(getRequestedFor(urlPathEqualTo("/foo")));
}
use of com.hotels.styx.api.HttpResponseStatus.OK in project styx by ExpediaGroup.
the class InterceptorPipelineBuilderTest method setUp.
@BeforeEach
public void setUp() {
environment = new Environment.Builder().registry(new MicrometerRegistry(new SimpleMeterRegistry())).configuration(StyxConfig.defaultConfig()).build();
plugins = List.of(namedPlugin("plug1", (request, chain) -> chain.proceed(request).map(response -> response.newBuilder().header("plug1", "1").build())), namedPlugin("plug2", (request, chain) -> chain.proceed(request).map(response -> response.newBuilder().header("plug2", "1").build())));
handler = mock(RoutingObject.class);
when(handler.handle(any(LiveHttpRequest.class), any(HttpInterceptor.Context.class))).thenReturn(Eventual.of(response(OK).build()));
}
Aggregations