use of reactor.ipc.netty.http.client.HttpClientResponse in project reactor-netty by reactor.
the class HttpServerTests method testConnectionCloseOnServerError.
@Test
public void testConnectionCloseOnServerError() throws Exception {
Flux<String> content = Flux.range(1, 3).doOnNext(i -> {
if (i == 3) {
throw new RuntimeException("test");
}
}).map(i -> "foo " + i);
NettyContext server = HttpServer.create(0).newHandler((req, res) -> res.sendString(content)).block(Duration.ofSeconds(30));
HttpClientResponse r = HttpClient.create(ops -> ops.port(server.address().getPort())).get("/").block(Duration.ofSeconds(30));
ByteBufFlux response = r.receive();
StepVerifier.create(response).expectNextCount(2).expectError(IOException.class).verify(Duration.ofSeconds(30));
FutureMono.from(r.context().channel().closeFuture()).block(Duration.ofSeconds(30));
r.dispose();
server.dispose();
}
use of reactor.ipc.netty.http.client.HttpClientResponse in project reactor-netty by reactor.
the class NettyOptionsTest method afterChannelInitAfterChannelGroup.
@Test
public void afterChannelInitAfterChannelGroup() {
// this test only differs from afterChannelInitThenChannelGroup in the order of the options
ChannelGroup group = new DefaultChannelGroup(null);
List<Channel> initializedChannels = new ArrayList<>();
NettyContext nettyContext = HttpServer.create(opt -> opt.channelGroup(group).afterChannelInit(initializedChannels::add)).start((req, resp) -> resp.sendNotFound()).getContext();
HttpClientResponse resp = HttpClient.create(opt -> opt.connectAddress(() -> nettyContext.address())).get("/", req -> req.failOnClientError(false).send()).block();
assertThat((Iterable<Channel>) group).hasSize(1).hasSameElementsAs(initializedChannels).doesNotContain(nettyContext.channel());
resp.dispose();
nettyContext.dispose();
}
use of reactor.ipc.netty.http.client.HttpClientResponse in project reactor-netty by reactor.
the class NettyOptionsTest method afterChannelInitThenChannelGroup.
@Test
public void afterChannelInitThenChannelGroup() {
ChannelGroup group = new DefaultChannelGroup(null);
List<Channel> initializedChannels = new ArrayList<>();
NettyContext nettyContext = HttpServer.create(opt -> opt.afterChannelInit(initializedChannels::add).channelGroup(group)).start((req, resp) -> resp.sendNotFound()).getContext();
HttpClientResponse resp = HttpClient.create(opt -> opt.connectAddress(() -> nettyContext.address())).get("/", req -> req.failOnClientError(false).send()).block();
assertThat((Iterable<Channel>) group).hasSize(1).hasSameElementsAs(initializedChannels).doesNotContain(nettyContext.channel());
resp.dispose();
nettyContext.dispose();
}
use of reactor.ipc.netty.http.client.HttpClientResponse in project reactor-netty by reactor.
the class NettyOptionsTest method afterNettyContextInit.
@Test
public void afterNettyContextInit() {
AtomicInteger readCount = new AtomicInteger();
ChannelInboundHandlerAdapter handler = new ChannelInboundHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
readCount.incrementAndGet();
super.channelRead(ctx, msg);
}
};
String handlerName = "test";
NettyContext nettyContext = HttpServer.create(opt -> opt.afterNettyContextInit(c -> c.addHandlerFirst(handlerName, handler))).start((req, resp) -> resp.sendNotFound()).getContext();
HttpClientResponse response1 = HttpClient.create(opt -> opt.connectAddress(() -> nettyContext.address())).get("/", req -> req.failOnClientError(false).send()).block();
assertThat(response1.status().code()).isEqualTo(404);
response1.dispose();
// the "main" context doesn't get enriched with handlers from options...
assertThat(nettyContext.channel().pipeline().names()).doesNotContain(handlerName);
// ...but the child channels that are created for requests are
assertThat(readCount.get()).isEqualTo(1);
HttpClientResponse response2 = HttpClient.create(opt -> opt.connectAddress(() -> nettyContext.address())).get("/", req -> req.failOnClientError(false).send()).block();
// reactor handler was applied and produced a response
assertThat(response2.status().code()).isEqualTo(404);
response2.dispose();
// BUT channelHandler wasn't applied a second time since not Shareable
assertThat(readCount.get()).isEqualTo(1);
nettyContext.dispose();
}
use of reactor.ipc.netty.http.client.HttpClientResponse in project reactor-netty by reactor.
the class HttpCompressionClientServerTests method serverCompressionDefault.
@Test
public void serverCompressionDefault() throws Exception {
HttpServer server = HttpServer.create(0);
NettyContext nettyContext = server.newHandler((in, out) -> out.sendString(Mono.just("reply"))).block(Duration.ofMillis(10_000));
HttpClient client = HttpClient.create(o -> o.connectAddress(() -> address(nettyContext)));
HttpClientResponse resp = client.get("/test", req -> req.header("Accept-Encoding", "gzip")).block();
assertThat(resp.responseHeaders().get("content-encoding")).isNull();
String reply = resp.receive().asString().blockFirst();
Assert.assertEquals("reply", reply);
resp.dispose();
nettyContext.dispose();
nettyContext.onClose().block();
}
Aggregations