From 8734d97728f0c91dc023f1edc6a2e967c3a9ae91 Mon Sep 17 00:00:00 2001 From: Violeta Georgieva Date: Thu, 28 Sep 2023 12:29:36 +0300 Subject: [PATCH] Ensure HttpClient#mapConnect() / #doOnRequestError() are called when HttpClient#headersWhen() is used (#2912) Fixes #2904 --- .../netty/http/client/HttpClientConnect.java | 2 +- .../netty/http/client/HttpClientTest.java | 28 +++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/reactor-netty-http/src/main/java/reactor/netty/http/client/HttpClientConnect.java b/reactor-netty-http/src/main/java/reactor/netty/http/client/HttpClientConnect.java index 5f127235e6..9db13a18fb 100644 --- a/reactor-netty-http/src/main/java/reactor/netty/http/client/HttpClientConnect.java +++ b/reactor-netty-http/src/main/java/reactor/netty/http/client/HttpClientConnect.java @@ -110,7 +110,7 @@ protected Mono connect() { Mono mono; if (config.deferredConf != null) { - return config.deferredConf.apply(Mono.just(config)) + mono = config.deferredConf.apply(Mono.just(config)) .flatMap(MonoHttpConnect::new); } else { diff --git a/reactor-netty-http/src/test/java/reactor/netty/http/client/HttpClientTest.java b/reactor-netty-http/src/test/java/reactor/netty/http/client/HttpClientTest.java index 65755bb963..6dbd05f8d9 100644 --- a/reactor-netty-http/src/test/java/reactor/netty/http/client/HttpClientTest.java +++ b/reactor-netty-http/src/test/java/reactor/netty/http/client/HttpClientTest.java @@ -1124,22 +1124,26 @@ void doOnError() { }) .bindNow(); + HttpClient client = createHttpClientForContextWithPort(); + doOnError(client.headers(h -> h.add("before", "test"))); + doOnError(client.headersWhen(h -> Mono.just(h.add("before", "test")))); + } + + private void doOnError(HttpClient client) { AtomicReference requestError1 = new AtomicReference<>(); AtomicReference responseError1 = new AtomicReference<>(); Mono content = - createHttpClientForContextWithPort() - .headers(h -> h.add("before", "test")) - .doOnRequestError((req, err) -> - requestError1.set(req.currentContextView().getOrDefault("test", "empty"))) - .doOnResponseError((res, err) -> - responseError1.set(res.currentContextView().getOrDefault("test", "empty"))) - .mapConnect(c -> c.contextWrite(Context.of("test", "success"))) - .get() - .uri("/") - .responseContent() - .aggregate() - .asString(); + client.doOnRequestError((req, err) -> + requestError1.set(req.currentContextView().getOrDefault("test", "empty"))) + .doOnResponseError((res, err) -> + responseError1.set(res.currentContextView().getOrDefault("test", "empty"))) + .mapConnect(c -> c.contextWrite(Context.of("test", "success"))) + .get() + .uri("/") + .responseContent() + .aggregate() + .asString(); StepVerifier.create(content) .verifyError(PrematureCloseException.class);