use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class HttpServerTests method sendFileSecure.
@Test
public void sendFileSecure() throws CertificateException, SSLException, URISyntaxException {
Path largeFile = Paths.get(getClass().getResource("/largeFile.txt").toURI());
SelfSignedCertificate ssc = new SelfSignedCertificate();
SslContext sslServer = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
SslContext sslClient = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
NettyContext context = HttpServer.create(opt -> opt.sslContext(sslServer)).newHandler((req, resp) -> resp.sendFile(largeFile)).block();
HttpClientResponse response = HttpClient.create(opt -> opt.port(context.address().getPort()).sslContext(sslClient)).get("/foo").block(Duration.ofSeconds(120));
context.dispose();
context.onClose().block();
String body = response.receive().aggregate().asString(StandardCharsets.UTF_8).block();
assertThat(body).startsWith("This is an UTF-8 file that is larger than 1024 bytes. " + "It contains accents like é.").contains("1024 mark here -><- 1024 mark here").endsWith("End of File");
}
use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class HttpServerTests method doTestIssue309.
private void doTestIssue309(String path, Consumer<? super HttpServerOptions.Builder> ops) {
NettyContext server = HttpServer.create(ops).newHandler((req, res) -> res.sendString(Mono.just("Should not be reached"))).block();
Mono<HttpResponseStatus> status = HttpClient.create(server.address().getPort()).get(path, req -> req.failOnClientError(false)).flatMap(res -> {
res.dispose();
HttpResponseStatus code = res.status();
return Mono.just(code);
});
StepVerifier.create(status).expectNextMatches(HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE::equals).expectComplete().verify();
server.dispose();
}
use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class HttpServerTests method flushOnComplete.
@Test
public void flushOnComplete() {
Flux<String> test = Flux.range(0, 100).map(n -> String.format("%010d", n));
NettyContext c = HttpServer.create(0).newHandler((req, resp) -> resp.sendString(test.map(s -> s + "\n"))).block(Duration.ofSeconds(30));
Flux<String> client = HttpClient.create(c.address().getPort()).get("/", out -> out.context(ctx -> ctx.addHandler(new LineBasedFrameDecoder(10)))).block(Duration.ofSeconds(30)).receive().asString();
StepVerifier.create(client).expectNextSequence(test.toIterable()).expectComplete().verify(Duration.ofSeconds(30));
c.dispose();
}
use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class NettyOptionsTest method afterChannelInit.
@Test
public void afterChannelInit() throws InterruptedException {
List<Channel> initializedChannels = new ArrayList<>();
NettyContext nettyContext = HttpServer.create(opt -> opt.afterChannelInit(initializedChannels::add)).start((req, resp) -> resp.sendNotFound()).getContext();
assertThat(initializedChannels).hasSize(0);
HttpClientResponse resp = HttpClient.create(opt -> opt.connectAddress(() -> nettyContext.address())).get("/", req -> req.failOnClientError(false).send()).block();
assertThat(initializedChannels).hasSize(1).doesNotContain(nettyContext.channel());
resp.dispose();
nettyContext.dispose();
}
use of reactor.ipc.netty.NettyContext in project reactor-netty by reactor.
the class NettyOptionsTest method channelIsAddedToChannelGroup.
@Test
public void channelIsAddedToChannelGroup() {
// create a ChannelGroup that never removes disconnected channels
ChannelGroup group = new DefaultChannelGroup(null) {
@Override
public boolean remove(Object o) {
System.err.println("removed " + o);
return false;
}
};
NettyContext nettyContext = HttpServer.create(opt -> opt.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).doesNotContain(nettyContext.channel()).hasSize(1);
resp.dispose();
nettyContext.dispose();
}
Aggregations