Skip to content

Commit 47c230b

Browse files
committed
Allow withTlsSocketStrategyFactory to work without SSL bundle
Update `HttpComponentsHttpClientBuilder` so that `withTlsSocketStrategyFactory` is called even if there is no SSL bundle. See gh-43422
1 parent 17b2edd commit 47c230b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/http/client/HttpComponentsHttpClientBuilder.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ public HttpComponentsHttpClientBuilder withSocketConfigCustomizer(
119119
* Return a new {@link HttpComponentsHttpClientBuilder} with a replacement
120120
* {@link TlsSocketStrategy} factory.
121121
* @param tlsSocketStrategyFactory the new factory used to create a
122-
* {@link TlsSocketStrategy} for a given {@link SslBundle}
122+
* {@link TlsSocketStrategy}. The function will be provided with a {@link SslBundle}
123+
* or {@code null} if no bundle is selected. Only non {@code null} results will be
124+
* applied.
123125
* @return a new {@link HttpComponentsHttpClientBuilder} instance
124126
*/
125127
public HttpComponentsHttpClientBuilder withTlsSocketStrategyFactory(
@@ -166,9 +168,9 @@ public CloseableHttpClient build(HttpClientSettings settings) {
166168
private PoolingHttpClientConnectionManager createConnectionManager(HttpClientSettings settings) {
167169
PoolingHttpClientConnectionManagerBuilder builder = PoolingHttpClientConnectionManagerBuilder.create()
168170
.useSystemProperties();
169-
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
171+
PropertyMapper map = PropertyMapper.get();
170172
builder.setDefaultSocketConfig(createSocketConfig(settings));
171-
map.from(settings::sslBundle).as(this.tlsSocketStrategyFactory).to(builder::setTlsSocketStrategy);
173+
map.from(settings::sslBundle).as(this.tlsSocketStrategyFactory).whenNonNull().to(builder::setTlsSocketStrategy);
172174
this.connectionManagerCustomizer.accept(builder);
173175
return builder.build();
174176
}

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/http/client/HttpComponentsSslBundleTlsStrategy.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ private HttpComponentsSslBundleTlsStrategy() {
3737
}
3838

3939
static DefaultClientTlsStrategy get(SslBundle sslBundle) {
40+
if (sslBundle == null) {
41+
return null;
42+
}
4043
SslOptions options = sslBundle.getOptions();
4144
SSLContext sslContext = sslBundle.createSslContext();
4245
return new DefaultClientTlsStrategy(sslContext, options.getEnabledProtocols(), options.getCiphers(), null,

0 commit comments

Comments
 (0)