Add customizer variant of requestFactorySettings

Add `requestFactorySettings` that accepts a `UnaryOperator` so that
the existing `requestFactorySettings` can be customized rather than
replaced.

Closes gh-43258
This commit is contained in:
Phillip Webb
2024-12-10 14:54:33 -08:00
parent 52992fb510
commit e72546d2a6
3 changed files with 46 additions and 2 deletions

View File

@@ -29,6 +29,7 @@ import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.http.client.ClientHttpRequestFactoryBuilder;
@@ -451,6 +452,22 @@ public class RestTemplateBuilder {
this.requestCustomizers);
}
/**
* Update the {@link ClientHttpRequestFactorySettings} using the given customizer.
* @param requestFactorySettingsCustomizer a {@link UnaryOperator} to update request
* factory settings
* @return a new builder instance
* @since 3.4.1
*/
public RestTemplateBuilder requestFactorySettings(
UnaryOperator<ClientHttpRequestFactorySettings> requestFactorySettingsCustomizer) {
Assert.notNull(requestFactorySettingsCustomizer, "ClientHttpRequestFactorySettingsCustomizer must not be null");
return new RestTemplateBuilder(requestFactorySettingsCustomizer.apply(this.requestFactorySettings),
this.detectRequestFactory, this.rootUri, this.messageConverters, this.interceptors,
this.requestFactoryBuilder, this.uriTemplateHandler, this.errorHandler, this.basicAuthentication,
this.defaultHeaders, this.customizers, this.requestCustomizers);
}
/**
* Sets the connection timeout on the underlying {@link ClientHttpRequestFactory}.
* @param connectTimeout the connection timeout