From 66d590cff227c37ddacae33110dbe76debce77b7 Mon Sep 17 00:00:00 2001 From: Olga Maciaszek-Sharma Date: Thu, 9 Jan 2025 14:17:05 +0100 Subject: [PATCH] Document disabling protocol upgrade for Apache HC5. Fixes gh-1141. --- .../ROOT/pages/spring-cloud-openfeign.adoc | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/modules/ROOT/pages/spring-cloud-openfeign.adoc b/docs/modules/ROOT/pages/spring-cloud-openfeign.adoc index 99a8150f..c17f72a0 100644 --- a/docs/modules/ROOT/pages/spring-cloud-openfeign.adoc +++ b/docs/modules/ROOT/pages/spring-cloud-openfeign.adoc @@ -146,7 +146,25 @@ When it comes to the Apache HttpClient 5-backed Feign clients, it's enough to en You can customize the HTTP client used by providing a bean of either `org.apache.hc.client5.http.impl.classic.CloseableHttpClient` when using Apache HC5. You can further customise http clients by setting values in the `spring.cloud.openfeign.httpclient.xxx` properties. The ones prefixed just with `httpclient` will work for all the clients, the ones prefixed with `httpclient.hc5` to Apache HttpClient 5, the ones prefixed with `httpclient.okhttp` to OkHttpClient and the ones prefixed with `httpclient.http2` to Http2Client. You can find a full list of properties you can customise in the appendix. -If you can not configure Apache HttpClient 5 by using properties, there is an `HttpClientBuilderCustomizer` interface for programmatic configuration. +If you can not configure Apache HttpClient 5 by using properties, there is an `HttpClient5FeignConfiguration.HttpClientBuilderCustomizer` interface for programmatic configuration. + +TIP: Apache HTTP Components `5.4` have changed defaults in the HttpClient relating to HTTP/1.1 TLS upgrades. Most proxy servers handle upgrades without issue, however, you may encounter issues with Envoy or Istio. If you need to restore previous behaviour, you can use `HttpClient5FeignConfiguration.HttpClientBuilderCustomizer` to do it, as shown in the example below. + +[source,java,indent=0] +---- +@Configuration +public class FooConfiguration { + + @Bean + public HttpClient5FeignConfiguration.HttpClientBuilderCustomizer httpClientBuilder() { + return (httpClientBuilder) -> { + RequestConfig.Builder requestConfigBuilder = RequestConfig.custom(); + requestConfigBuilder.setProtocolUpgradeEnabled(false); + httpClientBuilder.setDefaultRequestConfig(requestConfigBuilder.build()); + }; + } +} +---- TIP: Starting with Spring Cloud OpenFeign 4, the Feign Apache HttpClient 4 is no longer supported. We suggest using Apache HttpClient 5 instead.