use of reactor.netty.http.client.HttpClient in project spring-boot by spring-projects.
the class NettyRSocketServerFactoryTests method createSecureHttpClient.
private HttpClient createSecureHttpClient() {
HttpClient httpClient = createHttpClient();
Http11SslContextSpec sslContextSpec = Http11SslContextSpec.forClient().configure((builder) -> builder.sslProvider(SslProvider.JDK).trustManager(InsecureTrustManagerFactory.INSTANCE));
return httpClient.secure((spec) -> spec.sslContext(sslContextSpec));
}
use of reactor.netty.http.client.HttpClient in project reactor-netty by reactor.
the class EchoClient method main.
public static void main(String[] args) {
HttpClient client = HttpClient.create().port(PORT).wiretap(WIRETAP).compress(COMPRESS);
if (SECURE) {
Http11SslContextSpec http11SslContextSpec = Http11SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
client = client.secure(spec -> spec.sslContext(http11SslContextSpec));
}
String response = client.post().uri("/echo").send(ByteBufFlux.fromString(Mono.just("echo"))).responseContent().aggregate().asString().block();
System.out.println("Response: " + response);
}
use of reactor.netty.http.client.HttpClient in project reactor-netty by reactor.
the class HelloWorldClient method main.
public static void main(String[] args) {
HttpClient client = HttpClient.create().port(PORT).wiretap(WIRETAP).compress(COMPRESS);
if (SECURE) {
Http11SslContextSpec http11SslContextSpec = Http11SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
client = client.secure(spec -> spec.sslContext(http11SslContextSpec));
}
String response = client.get().uri("/hello").responseContent().aggregate().asString().block();
System.out.println("Response: " + response);
}
use of reactor.netty.http.client.HttpClient 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.client.HttpClient in project reactor-netty by reactor.
the class HttpServerTests method testMaxKeepAliveRequests.
@ParameterizedTest(name = "{displayName}({arguments})")
@ValueSource(ints = { -1, 1, 2 })
void testMaxKeepAliveRequests(int maxKeepAliveRequests) {
HttpServer server = createServer().handle((req, res) -> res.sendString(Mono.just("testMaxKeepAliveRequests")));
assertThat(server.configuration().maxKeepAliveRequests()).isEqualTo(-1);
server = server.maxKeepAliveRequests(maxKeepAliveRequests);
assertThat(server.configuration().maxKeepAliveRequests()).isEqualTo(maxKeepAliveRequests);
disposableServer = server.bindNow();
ConnectionProvider provider = ConnectionProvider.create("testMaxKeepAliveRequests", 1);
HttpClient client = createClient(provider, disposableServer.port());
Flux.range(0, 2).flatMap(i -> client.get().uri("/").responseSingle((res, bytes) -> bytes.asString().zipWith(Mono.just(res.responseHeaders().get(HttpHeaderNames.CONNECTION, "persistent"))))).collectList().as(StepVerifier::create).expectNextMatches(l -> {
boolean result = l.size() == 2 && "testMaxKeepAliveRequests".equals(l.get(0).getT1()) && "testMaxKeepAliveRequests".equals(l.get(1).getT1());
if (maxKeepAliveRequests == -1) {
return result && "persistent".equals(l.get(0).getT2()) && "persistent".equals(l.get(1).getT2());
} else if (maxKeepAliveRequests == 1) {
return result && "close".equals(l.get(0).getT2()) && "close".equals(l.get(1).getT2());
} else if (maxKeepAliveRequests == 2) {
return result && "persistent".equals(l.get(0).getT2()) && "close".equals(l.get(1).getT2());
}
return false;
}).expectComplete().verify(Duration.ofSeconds(5));
provider.disposeLater().block(Duration.ofSeconds(5));
}
Aggregations