use of reactor.netty.http.Http2SslContextSpec in project reactor-netty by reactor.
the class HttpServerTests method testIssue1286ConnectionCloseErrorResponse_H2.
@Test
void testIssue1286ConnectionCloseErrorResponse_H2() throws Exception {
Http2SslContextSpec serverCtx = Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey());
Http2SslContextSpec clientCtx = Http2SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
doTestIssue1286(server -> server.protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(serverCtx)), client -> client.protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(clientCtx)), true, true);
}
use of reactor.netty.http.Http2SslContextSpec in project reactor-netty by reactor.
the class HttpServerTests method testIssue1286_ServerHTTP11AndH2ClientHTTP11AndH2.
@Test
void testIssue1286_ServerHTTP11AndH2ClientHTTP11AndH2() throws Exception {
Http2SslContextSpec serverCtx = Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey());
Http2SslContextSpec clientCtx = Http2SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
doTestIssue1286(server -> server.protocol(HttpProtocol.H2, HttpProtocol.HTTP11).secure(spec -> spec.sslContext(serverCtx)), client -> client.protocol(HttpProtocol.H2, HttpProtocol.HTTP11).secure(spec -> spec.sslContext(clientCtx)), false, false);
}
use of reactor.netty.http.Http2SslContextSpec in project reactor-netty by reactor.
the class HttpServerTests method doTestIssue1978.
private void doTestIssue1978(HttpProtocol[] serverProtocols, HttpProtocol[] clientProtocols, @Nullable Http2SslContextSpec serverCtx, @Nullable Http2SslContextSpec clientCtx, long serverDelay, long clientDelay) throws Exception {
int count = 5;
CountDownLatch latch = new CountDownLatch(count);
Mono<String> mono = Mono.just("testIssue1978");
Mono<String> serverResponse = serverDelay == 0 ? mono : mono.delayElement(Duration.ofMillis(serverDelay));
HttpServer mainServer = HttpServer.create().protocol(serverProtocols).httpRequestDecoder(spec -> spec.h2cMaxContentLength(8 * 1024));
HttpServer server = serverCtx != null ? mainServer.secure(sslContextSpec -> sslContextSpec.sslContext(serverCtx)) : mainServer;
disposableServer = server.handle((req, res) -> {
req.withConnection(conn -> conn.channel().closeFuture().addListener(f -> latch.countDown()));
return res.sendString(serverResponse);
}).bindNow();
byte[] content = new byte[1024];
Random rndm = new Random();
rndm.nextBytes(content);
String strContent = new String(content, Charset.defaultCharset());
Flux<String> flux = Flux.just(strContent, strContent, strContent, strContent);
Flux<String> clientRequest = clientDelay == 0 ? flux : flux.delayElements(Duration.ofMillis(clientDelay));
HttpClient mainClient = HttpClient.create().port(disposableServer.port()).protocol(clientProtocols);
HttpClient client = clientCtx != null ? mainClient.secure(sslContextSpec -> sslContextSpec.sslContext(clientCtx)) : mainClient;
Flux.range(0, count).flatMap(i -> client.post().uri("/").send(ByteBufFlux.fromString(clientRequest)).responseContent().aggregate().asString()).blockLast(Duration.ofSeconds(10));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
}
use of reactor.netty.http.Http2SslContextSpec in project reactor-netty by reactor.
the class HttpServerTests method testIssue1286ConnectionClose_H2.
@Test
void testIssue1286ConnectionClose_H2() throws Exception {
Http2SslContextSpec serverCtx = Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey());
Http2SslContextSpec clientCtx = Http2SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
doTestIssue1286(server -> server.protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(serverCtx)), client -> client.protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(clientCtx)), true, false);
}
use of reactor.netty.http.Http2SslContextSpec in project reactor-netty by reactor.
the class DefaultPooledConnectionProviderTest method doTestIssue1982.
private void doTestIssue1982(HttpProtocol[] serverProtocols, HttpProtocol[] clientProtocols, @Nullable Http2SslContextSpec serverCtx, @Nullable Http2SslContextSpec clientCtx) throws Exception {
HttpServer server = serverCtx != null ? HttpServer.create().secure(sslContextSpec -> sslContextSpec.sslContext(serverCtx)) : HttpServer.create();
disposableServer = server.protocol(serverProtocols).http2Settings(h2 -> h2.maxConcurrentStreams(20)).handle((req, res) -> res.sendString(Mono.just("testIssue1982").delayElement(Duration.ofMillis(100)))).bindNow();
DefaultPooledConnectionProvider provider = (DefaultPooledConnectionProvider) ConnectionProvider.create("", 5);
CountDownLatch latch = new CountDownLatch(1);
AtomicInteger counter = new AtomicInteger();
HttpClient mainClient = clientCtx != null ? HttpClient.create(provider).port(disposableServer.port()).secure(sslContextSpec -> sslContextSpec.sslContext(clientCtx)) : HttpClient.create(provider).port(disposableServer.port());
HttpClient client = mainClient.protocol(clientProtocols).observe((conn, state) -> {
if (state == ConnectionObserver.State.CONNECTED) {
counter.incrementAndGet();
}
if (state == ConnectionObserver.State.RELEASED && counter.decrementAndGet() == 0) {
latch.countDown();
}
});
try {
Flux.range(0, 80).flatMap(i -> client.get().uri("/").responseContent().aggregate().asString()).blockLast(Duration.ofSeconds(10));
assertThat(latch.await(5, TimeUnit.SECONDS)).isTrue();
@SuppressWarnings({ "unchecked", "rawtypes" }) InstrumentedPool<DefaultPooledConnectionProvider.PooledConnection> channelPool = provider.channelPools.values().toArray(new InstrumentedPool[0])[0];
InstrumentedPool.PoolMetrics metrics = channelPool.metrics();
assertThat(metrics.acquiredSize()).isEqualTo(0);
assertThat(metrics.allocatedSize()).isEqualTo(metrics.idleSize());
} finally {
provider.disposeLater().block(Duration.ofSeconds(5));
}
}
Aggregations