use of reactor.netty.http.Http2SslContextSpec in project reactor-netty by reactor.
the class HttpClientTest method testConnectionLifeTimeElasticPoolHttp2.
@Test
void testConnectionLifeTimeElasticPoolHttp2() throws Exception {
Http2SslContextSpec serverCtx = Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey());
Http2SslContextSpec clientCtx = Http2SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
ConnectionProvider provider = ConnectionProvider.builder("testConnectionLifeTimeElasticPoolHttp2").maxConnections(Integer.MAX_VALUE).maxLifeTime(Duration.ofMillis(30)).build();
try {
ChannelId[] ids = doTestConnectionLifeTime(createServer().protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(serverCtx)), createClient(provider, () -> disposableServer.address()).protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(clientCtx)));
assertThat(ids[0]).isNotEqualTo(ids[1]);
} finally {
provider.disposeLater().block(Duration.ofSeconds(5));
}
}
use of reactor.netty.http.Http2SslContextSpec in project reactor-netty by reactor.
the class HttpServerPostFormTests method data.
static Object[][] data() throws Exception {
SelfSignedCertificate cert = new SelfSignedCertificate();
Http2SslContextSpec serverCtx = Http2SslContextSpec.forServer(cert.certificate(), cert.privateKey());
Http2SslContextSpec clientCtx = Http2SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
HttpServer server = HttpServer.create().httpRequestDecoder(spec -> spec.h2cMaxContentLength(32 * 1024));
HttpServer h2Server = server.protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(serverCtx));
HttpServer h2Http1Server = server.protocol(HttpProtocol.H2, HttpProtocol.HTTP11).secure(spec -> spec.sslContext(serverCtx));
HttpClient client = HttpClient.create();
HttpClient h2Client = client.protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(clientCtx));
HttpClient h2Http1Client = client.protocol(HttpProtocol.H2, HttpProtocol.HTTP11).secure(spec -> spec.sslContext(clientCtx));
return new Object[][] { { server, client }, { server.protocol(HttpProtocol.H2C), client.protocol(HttpProtocol.H2C) }, { server.protocol(HttpProtocol.H2C, HttpProtocol.HTTP11), client.protocol(HttpProtocol.H2C, HttpProtocol.HTTP11) }, { h2Server, h2Client }, { h2Http1Server, h2Http1Client } };
}
use of reactor.netty.http.Http2SslContextSpec in project reactor-netty by reactor.
the class HttpRedirectTest method testHttp2Redirect.
@Test
void testHttp2Redirect() {
Http2SslContextSpec serverCtx = Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey());
Http2SslContextSpec clientCtx = Http2SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
disposableServer = createServer().host("localhost").protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(serverCtx)).route(r -> r.get("/1", (req, res) -> res.sendRedirect("/3")).get("/3", (req, res) -> res.status(200).sendString(Mono.just("OK")))).wiretap(true).bindNow();
Tuple2<String, Integer> response = createClient(disposableServer::address).followRedirect(true).protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(clientCtx)).get().uri("/1").responseSingle((res, bytes) -> bytes.asString().zipWith(Mono.just(res.status().code()))).block(Duration.ofSeconds(30));
assertThat(response).isNotNull();
assertThat(response.getT2()).isEqualTo(200);
assertThat(response.getT1()).isEqualTo("OK");
}
use of reactor.netty.http.Http2SslContextSpec in project reactor-netty by reactor.
the class HttpClientTest method testConnectionNoLifeTimeFixedPoolHttp2.
@Test
void testConnectionNoLifeTimeFixedPoolHttp2() throws Exception {
Http2SslContextSpec serverCtx = Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey());
Http2SslContextSpec clientCtx = Http2SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
ConnectionProvider provider = ConnectionProvider.builder("testConnectionNoLifeTimeFixedPoolHttp2").maxConnections(1).pendingAcquireTimeout(Duration.ofMillis(100)).build();
try {
ChannelId[] ids = doTestConnectionLifeTime(createServer().protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(serverCtx)), createClient(provider, () -> disposableServer.address()).protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(clientCtx)));
assertThat(ids[0]).isEqualTo(ids[1]);
} finally {
provider.disposeLater().block(Duration.ofSeconds(5));
}
}
use of reactor.netty.http.Http2SslContextSpec in project reactor-netty by reactor.
the class ConnectionPoolTests method prepare.
@BeforeAll
static void prepare() throws CertificateException {
HttpServer server = createServer();
server1 = server.handle((req, res) -> res.sendString(Mono.just("server1-ConnectionPoolTests"))).bindNow();
server2 = server.handle((req, res) -> res.sendString(Mono.just("server2-ConnectionPoolTests"))).bindNow();
SelfSignedCertificate cert = new SelfSignedCertificate();
Http11SslContextSpec http11SslContextSpec = Http11SslContextSpec.forServer(cert.certificate(), cert.privateKey());
Http2SslContextSpec http2SslContextSpec = Http2SslContextSpec.forServer(cert.certificate(), cert.privateKey());
server3 = server.protocol(HttpProtocol.H2, HttpProtocol.HTTP11).secure(spec -> spec.sslContext(http2SslContextSpec)).handle((req, res) -> res.sendString(Mono.just("server3-ConnectionPoolTests"))).bindNow();
server4 = server.secure(spec -> spec.sslContext(http11SslContextSpec)).handle((req, res) -> res.sendString(Mono.just("server4-ConnectionPoolTests"))).bindNow();
provider = ConnectionProvider.create("ConnectionPoolTests", 1);
loop = LoopResources.create("ConnectionPoolTests");
metricsRecorderSupplier = () -> Mockito.mock(ChannelMetricsRecorder.class);
}
Aggregations