use of reactor.netty.http.server.HttpServerConfig in project reactor-netty by reactor.
the class HttpProtocolsTests method data.
static Object[][] data(boolean onlyCompatible, boolean disablePool, boolean useCustomPool) throws Exception {
SelfSignedCertificate cert = new SelfSignedCertificate();
Http11SslContextSpec serverCtxHttp11 = Http11SslContextSpec.forServer(cert.certificate(), cert.privateKey());
Http11SslContextSpec clientCtxHttp11 = Http11SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
Http2SslContextSpec serverCtxHttp2 = Http2SslContextSpec.forServer(cert.certificate(), cert.privateKey());
Http2SslContextSpec clientCtxHttp2 = Http2SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
HttpServer _server = createServer().httpRequestDecoder(spec -> spec.h2cMaxContentLength(256));
HttpServer[] servers = new HttpServer[] { // by default protocol is HTTP/1.1
_server, _server.protocol(HttpProtocol.H2C), _server.protocol(HttpProtocol.HTTP11, HttpProtocol.H2C), // by default protocol is HTTP/1.1
_server.secure(spec -> spec.sslContext(serverCtxHttp11)), _server.secure(spec -> spec.sslContext(serverCtxHttp2)).protocol(HttpProtocol.H2), _server.secure(spec -> spec.sslContext(serverCtxHttp2)).protocol(HttpProtocol.HTTP11, HttpProtocol.H2) };
HttpClient _client;
if (disablePool) {
_client = HttpClient.newConnection();
} else if (useCustomPool) {
_client = HttpClient.create(provider);
} else {
_client = HttpClient.create();
}
_client = _client.wiretap(true);
HttpClient[] clients = new HttpClient[] { // by default protocol is HTTP/1.1
_client, _client.protocol(HttpProtocol.H2C), _client.protocol(HttpProtocol.HTTP11, HttpProtocol.H2C), // by default protocol is HTTP/1.1
_client.secure(spec -> spec.sslContext(clientCtxHttp11)), _client.secure(spec -> spec.sslContext(clientCtxHttp2)).protocol(HttpProtocol.H2), _client.secure(spec -> spec.sslContext(clientCtxHttp2)).protocol(HttpProtocol.HTTP11, HttpProtocol.H2) };
Flux<HttpServer> f1 = Flux.fromArray(servers).concatMap(o -> Flux.just(o).repeat(clients.length - 1));
Flux<HttpClient> f2 = Flux.fromArray(clients).repeat(servers.length - 1);
return Flux.zip(f1, f2).filter(tuple2 -> {
if (onlyCompatible) {
HttpServerConfig serverConfig = tuple2.getT1().configuration();
HttpClientConfig clientConfig = tuple2.getT2().configuration();
List<HttpProtocol> serverProtocols = Arrays.asList(serverConfig.protocols());
List<HttpProtocol> clientProtocols = Arrays.asList(clientConfig.protocols());
if (serverConfig.isSecure() != clientConfig.isSecure()) {
return false;
} else if (serverProtocols.size() == 1 && serverProtocols.get(0) == HttpProtocol.H2C && clientProtocols.size() == 2) {
return false;
}
return serverProtocols.containsAll(clientProtocols) || clientProtocols.containsAll(serverProtocols);
}
return true;
}).map(Tuple2::toArray).collectList().block(Duration.ofSeconds(30)).toArray(new Object[0][2]);
}
use of reactor.netty.http.server.HttpServerConfig in project reactor-netty by reactor.
the class HttpProtocolsTests method testGetRequest.
@ParameterizedAllCombinationsTest
void testGetRequest(HttpServer server, HttpClient client) {
HttpServerConfig serverConfig = server.configuration();
HttpClientConfig clientConfig = client.configuration();
List<HttpProtocol> serverProtocols = Arrays.asList(serverConfig.protocols());
List<HttpProtocol> clientProtocols = Arrays.asList(clientConfig.protocols());
disposableServer = server.handle((req, res) -> {
boolean secure = "https".equals(req.scheme());
if (serverConfig.isSecure() != secure) {
return res.status(400).send();
}
return res.sendString(Mono.just("Hello"));
}).bindNow();
Mono<String> response = client.port(disposableServer.port()).get().uri("/").responseContent().aggregate().asString();
if (serverConfig.isSecure() != clientConfig.isSecure()) {
StepVerifier.create(response).expectError().verify(Duration.ofSeconds(30));
} else if (serverProtocols.size() == 1 && serverProtocols.get(0) == HttpProtocol.H2C && clientProtocols.size() == 2) {
StepVerifier.create(response).expectError().verify(Duration.ofSeconds(30));
} else if (serverProtocols.containsAll(clientProtocols) || clientProtocols.containsAll(serverProtocols)) {
StepVerifier.create(response).expectNext("Hello").expectComplete().verify(Duration.ofSeconds(30));
} else {
StepVerifier.create(response).expectError().verify(Duration.ofSeconds(30));
}
}
use of reactor.netty.http.server.HttpServerConfig in project reactor-netty by reactor.
the class HttpProtocolsTests method doTestPostRequest.
private void doTestPostRequest(HttpServer server, HttpClient client, boolean externalThread) {
HttpServerConfig serverConfig = server.configuration();
HttpClientConfig clientConfig = client.configuration();
List<HttpProtocol> serverProtocols = Arrays.asList(serverConfig.protocols());
List<HttpProtocol> clientProtocols = Arrays.asList(clientConfig.protocols());
disposableServer = server.handle((req, res) -> {
boolean secure = "https".equals(req.scheme());
if (serverConfig.isSecure() != secure) {
return res.status(400).send();
}
Flux<ByteBuf> publisher = req.receive().retain();
if (externalThread) {
publisher = publisher.subscribeOn(Schedulers.boundedElastic());
}
return res.send(publisher);
}).bindNow();
Mono<String> response = client.port(disposableServer.port()).post().uri("/").send(ByteBufFlux.fromString(Mono.just("Hello"))).responseContent().aggregate().asString();
if (serverConfig.isSecure() != clientConfig.isSecure()) {
StepVerifier.create(response).expectError().verify(Duration.ofSeconds(30));
} else if (serverProtocols.size() == 1 && serverProtocols.get(0) == HttpProtocol.H2C && clientProtocols.size() == 2) {
StepVerifier.create(response).expectError().verify(Duration.ofSeconds(30));
} else if (serverProtocols.containsAll(clientProtocols) || clientProtocols.containsAll(serverProtocols)) {
StepVerifier.create(response).expectNext("Hello").expectComplete().verify(Duration.ofSeconds(30));
} else {
StepVerifier.create(response).expectError().verify(Duration.ofSeconds(30));
}
}
Aggregations