Skip to content

Commit 1f100f2

Browse files
committed
allow customization of 'hc5ConnectionManager' bean in 'HttpClient5FeignConfiguration' via new customizer supplied as beans
Signed-off-by: Severin Kistler <kistlerseverin@gmail.com>
1 parent 4267eac commit 1f100f2

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/clientconfig/HttpClient5FeignConfiguration.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ public class HttpClient5FeignConfiguration {
7171

7272
@Bean
7373
@ConditionalOnMissingBean(HttpClientConnectionManager.class)
74-
public HttpClientConnectionManager hc5ConnectionManager(FeignHttpClientProperties httpClientProperties) {
75-
return PoolingHttpClientConnectionManagerBuilder.create()
74+
public HttpClientConnectionManager hc5ConnectionManager(FeignHttpClientProperties httpClientProperties,
75+
ObjectProvider<List<HttpClientConnectionManagerBuilderCustomizer>> customizerProvider) {
76+
PoolingHttpClientConnectionManagerBuilder httpClientConnectionManager = PoolingHttpClientConnectionManagerBuilder.create()
7677
.setSSLSocketFactory(httpsSSLConnectionSocketFactory(httpClientProperties.isDisableSslValidation()))
7778
.setMaxConnTotal(httpClientProperties.getMaxConnections())
7879
.setMaxConnPerRoute(httpClientProperties.getMaxConnectionsPerRoute())
@@ -84,8 +85,11 @@ public HttpClientConnectionManager hc5ConnectionManager(FeignHttpClientPropertie
8485
.setDefaultSocketConfig(SocketConfig.custom()
8586
.setSoTimeout(Timeout.of(httpClientProperties.getHc5().getSocketTimeout(),
8687
httpClientProperties.getHc5().getSocketTimeoutUnit()))
87-
.build())
88-
.build();
88+
.build());
89+
90+
customizerProvider.getIfAvailable(List::of).forEach(c -> c.customize(httpClientConnectionManager));
91+
92+
return httpClientConnectionManager.build();
8993
}
9094

9195
@Bean
@@ -174,4 +178,21 @@ public interface HttpClientBuilderCustomizer {
174178

175179
}
176180

181+
/**
182+
* Callback interface that customize {@link HttpClientBuilder} objects before
183+
* HttpClientConnectionManager created.
184+
*
185+
* @author Severin Kistler
186+
* @since 5.1.0
187+
*/
188+
public interface HttpClientConnectionManagerBuilderCustomizer {
189+
190+
/**
191+
* Customize PoolingHttpClientConnectionManagerBuilder.
192+
* @param builder the {@code PoolingHttpClientConnectionManagerBuilder} to customize
193+
*/
194+
void customize(PoolingHttpClientConnectionManagerBuilder builder);
195+
196+
}
197+
177198
}

0 commit comments

Comments
 (0)