Introduce ClientHttpConnectorBuilder support

Add a new `ClientHttpConnectorBuilder` interface to support the
creation of `ClientHttpConnector` instances. The new code is similar
to the `ClientHttpRequestFactoryBuilder` interface that was added to
Spring Boot 3.4.

The `ClientHttpConnectorBuilder` is a functional interface with
additional static factory methods for the various supported
`ClientHttpConnector` types. Each type has it's own builder
which to support client specific customization.

The previous auto-configuration has been relocated to the
`org.springframework.boot.autoconfigure.http.client.reactive`
package and updated to make use of the builder.

Closes gh-43079
This commit is contained in:
Phillip Webb
2025-03-27 14:24:39 -07:00
parent 4034725e38
commit 983e7b637b
68 changed files with 3682 additions and 1182 deletions

View File

@@ -52,6 +52,45 @@ You can learn more about the {url-spring-framework-docs}/web/webflux-webclient/c
[[io.rest-client.webclient.configuration]]
=== Global HTTP Connector Configuration
If the auto-detected javadoc:org.springframework.http.client.reactive.ClientHttpConnector[] does not meet your needs, you can use the configprop:spring.http.reactiveclient.settings.connector[] property to pick a specific connector.
For example, if you have Reactor Netty on your classpath, but you prefer Jetty's javadoc:org.eclipse.jetty.client.HttpClient[] you can add the following:
[configprops,yaml]
----
spring:
http:
reactiveclient:
settings:
connector: jetty
----
You can also set properties to change defaults that will be applied to all reactive connectors.
For example, you may want to change timeouts and if redirects are followed:
[configprops,yaml]
----
spring:
http:
reactiveclient:
settings:
connect-timeout: 2s
read-timeout: 1s
redirects: dont-follow
----
For more complex customizations, you can use javadoc:org.springframework.boot.autoconfigure.http.client.reactive.ClientHttpConnectorBuilderCustomizer[] or declare your own javadoc:org.springframework.boot.http.client.reactive.ClientHttpConnectorBuilder[] bean which will cause auto-configuration to back off.
This can be useful when you need to customize some of the internals of the underlying HTTP library.
For example, the following will use a JDK client configured with a specific javadoc:java.net.ProxySelector[]:
include-code::MyConnectorHttpConfiguration[]
[[io.rest-client.webclient.customization]]
=== WebClient Customization