mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Apply SslConfigurer in addition to configured mappers
Update `ReactorClientHttpConnectorFactory` to that SSL configuration is applied in addition to any configured mappers. Prior to this commit, SSL configuration would prevent configured mappers from being applied. See gh-35914
This commit is contained in:
parent
b770ffc160
commit
e6b5322f3e
@ -55,14 +55,14 @@ class ReactorClientHttpConnectorFactory implements ClientHttpConnectorFactory<Re
|
||||
|
||||
@Override
|
||||
public ReactorClientHttpConnector createClientHttpConnector(SslBundle sslBundle) {
|
||||
ReactorNettyHttpClientMapper mapper = this.mappers.get()
|
||||
.reduce((before, after) -> (client) -> after.configure(before.configure(client)))
|
||||
.orElse((client) -> client);
|
||||
if (sslBundle != null) {
|
||||
mapper = new SslConfigurer(sslBundle)::configure;
|
||||
}
|
||||
return new ReactorClientHttpConnector(this.reactorResourceFactory, mapper::configure);
|
||||
final ReactorNettyHttpClientMapper mapper =
|
||||
Stream.concat(
|
||||
this.mappers.get(),
|
||||
Stream.ofNullable(sslBundle != null ? (ReactorNettyHttpClientMapper) new SslConfigurer(sslBundle)::configure : null))
|
||||
.reduce((before, after) -> (client) -> after.configure(before.configure(client)))
|
||||
.orElse((client) -> client);
|
||||
|
||||
return new ReactorClientHttpConnector(this.reactorResourceFactory, mapper::configure);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,6 +24,10 @@ import org.eclipse.jetty.util.thread.Scheduler;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.ssl.SslBundle;
|
||||
import org.springframework.boot.ssl.SslBundleKey;
|
||||
import org.springframework.boot.ssl.jks.JksSslStoreBundle;
|
||||
import org.springframework.boot.ssl.jks.JksSslStoreDetails;
|
||||
import org.springframework.boot.test.context.FilteredClassLoader;
|
||||
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@ -80,11 +84,14 @@ class ClientHttpConnectorFactoryConfigurationTests {
|
||||
|
||||
@Test
|
||||
void shouldApplyHttpClientMapper() {
|
||||
JksSslStoreDetails storeDetails = JksSslStoreDetails.forLocation("classpath:test.jks");
|
||||
JksSslStoreBundle stores = new JksSslStoreBundle(storeDetails, storeDetails);
|
||||
SslBundle sslBundle = SslBundle.of(stores, SslBundleKey.of("password"));
|
||||
new ReactiveWebApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(ClientHttpConnectorFactoryConfiguration.ReactorNetty.class))
|
||||
.withUserConfiguration(CustomHttpClientMapper.class)
|
||||
.run((context) -> {
|
||||
context.getBean(ReactorClientHttpConnectorFactory.class).createClientHttpConnector();
|
||||
context.getBean(ReactorClientHttpConnectorFactory.class).createClientHttpConnector(sslBundle);
|
||||
assertThat(CustomHttpClientMapper.called).isTrue();
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user