Add 'Global HTTP Client Configuration' reference docs section

Update documentation with information on how to configure the HTTP
client globally.

Closes gh-42888
This commit is contained in:
Phillip Webb
2024-10-25 17:47:38 -07:00
parent e1b5935507
commit 2208c67f22
3 changed files with 96 additions and 3 deletions

View File

@@ -112,6 +112,8 @@ To make an application-wide, additive customization to all `RestClient.Builder`
Finally, you can fall back to the original API and use `RestClient.create()`.
In that case, no auto-configuration or `RestClientCustomizer` is applied.
TIP: You can also change the xref:io/rest-client.adoc#io.rest-client.clienthttprequestfactory.configuration[global HTTP client configuration].
[[io.rest-client.restclient.ssl]]
@@ -175,6 +177,8 @@ include-code::MyRestTemplateBuilderConfiguration[]
The most extreme (and rarely used) option is to create your own `RestTemplateBuilder` bean without using a configurer.
In addition to replacing the auto-configured builder, this also prevents any `RestTemplateCustomizer` beans from being used.
TIP: You can also change the xref:io/rest-client.adoc#io.rest-client.clienthttprequestfactory.configuration[global HTTP client configuration].
[[io.rest-client.resttemplate.ssl]]
@@ -195,7 +199,44 @@ In order of preference, the following clients are supported:
. Apache HttpClient
. Jetty HttpClient
. Reactor Netty HttpClient
. OkHttp (deprecated)
. Simple JDK client (`HttpURLConnection`)
. JDK client (`java.net.http.HttpClient`)
. Simple JDK client (`java.net.HttpURLConnection`)
If multiple clients are available on the classpath, and not global configuration is provided, the most preferred client will be used.
[[io.rest-client.clienthttprequestfactory.configuration]]
=== Global HTTP Client Configuration
If the the auto-detected HTTP client does not meet your needs, you can use the configprop:spring.http.client.factory[] property to pick a specific factory.
For example, if you have Apache HttpClient on your classpath, but you prefer Jetty's `HttpClient` you can add use the following:
[configprops,yaml]
----
spring:
http:
client:
factory: jetty
----
You can also set properties to change defaults that will be applied to all clients.
For example, you may want to change timeouts and if redirects are followed:
[configprops,yaml]
----
spring:
http:
client:
connect-timeout: 2s
read-timeout: 1s
redirects: dont-follow
----
For more complex customizations, you can declare your own `ClientHttpRequestFactoryBuilder` 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 `java.net.ProxySelector`:
include-code::MyClientHttpConfiguration[]
If multiple clients are available on the classpath, the most preferred client will be used.