use of reactor.ipc.netty.http.client.HttpClientResponse in project reactor-netty by reactor.
the class HttpCompressionClientServerTests method compressionServerEnabledClientDisabledIsNone.
@Test
public void compressionServerEnabledClientDisabledIsNone() throws Exception {
HttpServer server = HttpServer.create(o -> o.port(0).compression(true));
String serverReply = "reply";
NettyContext nettyContext = server.newHandler((in, out) -> out.sendString(Mono.just(serverReply))).block(Duration.ofMillis(10_000));
HttpClient client = HttpClient.create(o -> o.compression(false).connectAddress(() -> address(nettyContext)));
HttpClientResponse resp = client.get("/test").block();
String reply = resp.receive().asString().blockFirst();
assertThat(resp.responseHeaders().get("Content-Encoding")).isNull();
assertThat(reply).isEqualTo(serverReply);
resp.dispose();
nettyContext.dispose();
nettyContext.onClose().block();
}
use of reactor.ipc.netty.http.client.HttpClientResponse in project reactor-netty by reactor.
the class HttpErrorTests method test.
@Test
public void test() {
NettyContext server = HttpServer.create(0).newRouter(httpServerRoutes -> httpServerRoutes.get("/", (httpServerRequest, httpServerResponse) -> {
return httpServerResponse.sendString(Mono.error(new IllegalArgumentException()));
})).block(Duration.ofSeconds(30));
HttpClient client = HttpClient.create(opt -> opt.host("localhost").port(server.address().getPort()).disablePool());
HttpClientResponse r = client.get("/").block(Duration.ofSeconds(30));
Mono<List<String>> result = r.receive().asString(StandardCharsets.UTF_8).collectList();
StepVerifier.create(result).expectError(IOException.class).verify(Duration.ofSeconds(30));
System.out.println("END");
FutureMono.from(r.context().channel().closeFuture()).block(Duration.ofSeconds(30));
r.dispose();
server.dispose();
}
use of reactor.ipc.netty.http.client.HttpClientResponse in project reactor-netty by reactor.
the class ChannelOperationsHandlerTest method doTestPublisherSenderOnCompleteFlushInProgress.
private void doTestPublisherSenderOnCompleteFlushInProgress(boolean useScheduler) {
NettyContext server = HttpServer.create(0).newHandler((req, res) -> req.receive().asString().doOnNext(System.err::println).then(res.status(200).sendHeaders().then())).block(Duration.ofSeconds(30));
Flux<String> flux = Flux.range(1, 257).map(count -> count + "");
if (useScheduler) {
flux.publishOn(Schedulers.single());
}
Mono<HttpClientResponse> client = HttpClient.create(server.address().getPort()).post("/", req -> req.sendString(flux));
StepVerifier.create(client).expectNextMatches(res -> {
res.dispose();
return res.status().code() == 200;
}).expectComplete().verify(Duration.ofSeconds(30));
server.dispose();
}
use of reactor.ipc.netty.http.client.HttpClientResponse in project reactor-netty by reactor.
the class ChannelOperationsHandlerTest method testChannelInactiveThrowsIOException.
@Test
public void testChannelInactiveThrowsIOException() throws Exception {
ExecutorService threadPool = Executors.newCachedThreadPool();
int abortServerPort = SocketUtils.findAvailableTcpPort();
ConnectionAbortServer abortServer = new ConnectionAbortServer(abortServerPort);
threadPool.submit(abortServer);
if (!abortServer.await(10, TimeUnit.SECONDS)) {
throw new IOException("Fail to start test server");
}
Mono<HttpClientResponse> response = HttpClient.create(ops -> ops.host("localhost").port(abortServerPort)).get("/", req -> req.sendString(Flux.just("a", "b", "c")));
StepVerifier.create(response.log()).expectErrorMessage("Connection closed prematurely").verify();
abortServer.close();
}
use of reactor.ipc.netty.http.client.HttpClientResponse in project cf-java-client by cloudfoundry.
the class NetworkLogging method response.
public static Function<Mono<HttpClientResponse>, Mono<HttpClientResponse>> response(String uri) {
if (!RESPONSE_LOGGER.isDebugEnabled()) {
return inbound -> inbound;
}
AtomicLong startTimeHolder = new AtomicLong();
AtomicReference<HttpClientResponse> responseHolder = new AtomicReference<>();
return inbound -> inbound.doOnSubscribe(s -> startTimeHolder.set(System.currentTimeMillis())).doOnNext(responseHolder::set).doFinally(signalType -> {
String elapsed = TimeUtils.asTime(System.currentTimeMillis() - startTimeHolder.get());
Optional.ofNullable(responseHolder.get()).ifPresent(response -> {
List<String> warnings = response.responseHeaders().getAll(CF_WARNINGS);
if (warnings.isEmpty()) {
RESPONSE_LOGGER.debug("{} {} ({})", response.status().code(), uri, elapsed);
} else {
RESPONSE_LOGGER.warn("{} {} ({}) [{}]", response.status().code(), uri, elapsed, warnings.stream().collect(Collectors.joining(", ")));
}
});
});
}
Aggregations