Skip to content

Commit

Permalink
Ensure HttpClient#mapConnect() / #doOnRequestError() are called when …
Browse files Browse the repository at this point in the history
…HttpClient#headersWhen() is used (#2912)

Fixes #2904
  • Loading branch information
violetagg committed Sep 28, 2023
1 parent b6aa478 commit 8734d97
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected Mono<? extends Connection> connect() {

Mono<? extends Connection> mono;
if (config.deferredConf != null) {
return config.deferredConf.apply(Mono.just(config))
mono = config.deferredConf.apply(Mono.just(config))
.flatMap(MonoHttpConnect::new);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> requestError1 = new AtomicReference<>();
AtomicReference<String> responseError1 = new AtomicReference<>();

Mono<String> 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);
Expand Down

0 comments on commit 8734d97

Please sign in to comment.