Defer ExchangeFilterFunction to subscription time

Previously fixed in 5.2 via d46359. Now also backported to 5.1.x.

Closes gh-23909
This commit is contained in:
Rossen Stoyanchev
2019-11-06 21:31:42 +00:00
parent ca3440cb42
commit 1a057654b2
3 changed files with 54 additions and 17 deletions

View File

@@ -317,7 +317,8 @@ class DefaultWebClient implements WebClient {
ClientRequest request = (this.inserter != null ?
initRequestBuilder().body(this.inserter).build() :
initRequestBuilder().build());
return exchangeFunction.exchange(request).switchIfEmpty(NO_HTTP_CLIENT_RESPONSE_ERROR);
return Mono.defer(() -> exchangeFunction.exchange(request))
.switchIfEmpty(NO_HTTP_CLIENT_RESPONSE_ERROR);
}
private ClientRequest.Builder initRequestBuilder() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,9 @@ import reactor.core.publisher.Mono;
import org.springframework.util.Assert;
/**
* Represents a function that filters an{@linkplain ExchangeFunction exchange function}.
* Represents a function that filters an {@linkplain ExchangeFunction exchange function}.
* <p>The filter is executed when a {@code Subscriber} subscribes to the
* {@code Publisher} returned by the {@code WebClient}.
*
* @author Arjen Poutsma
* @since 5.0