Skip to content

Commit

Permalink
Merge pull request #1147 from cloudfoundry/gh_issue_1143
Browse files Browse the repository at this point in the history
  • Loading branch information
pivotal-david-osullivan authored Apr 27, 2022
2 parents 00faecf + e427d97 commit 7a2d445
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import reactor.netty.resources.ConnectionProvider;
import reactor.netty.resources.LoopResources;
import reactor.netty.tcp.SslProvider;
import reactor.netty.tcp.SslProvider.DefaultConfigurationType;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
Expand Down Expand Up @@ -103,10 +102,10 @@ public Integer getConnectionPoolSize() {
@Override
@Value.Default
public HttpClient getHttpClient() {
HttpClient client = createHttpClient().compress(true)
.secure(this::configureSsl);
HttpClient client = configureHttpClient(createHttpClient().compress(true)
.secure(this::configureSsl));

return getAdditionalHttpClientConfiguration().map(configuration -> configuration.apply(configureHttpClient(client)))
return getAdditionalHttpClientConfiguration().map(configuration -> configuration.apply(client))
.orElse(client);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@

package org.cloudfoundry.reactor;

import io.netty.handler.logging.ByteBufFormat;
import io.netty.handler.logging.LogLevel;
import org.junit.After;
import org.junit.Test;
import reactor.netty.http.client.HttpClient;
import reactor.netty.transport.ProxyProvider;
import reactor.test.StepVerifier;

import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.Optional;

import static io.netty.handler.codec.http.HttpMethod.GET;
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
import static org.assertj.core.api.Assertions.assertThat;

public final class DefaultConnectionContextTest extends AbstractRestTest {

Expand Down Expand Up @@ -85,4 +92,35 @@ public void multipleInstances() {
second.dispose();
}

@Test
public void configurationAlwaysApplied() {
DefaultConnectionContext ctx = DefaultConnectionContext.builder()
.apiHost("api.example.com")
.keepAlive(true)
.proxyConfiguration(
ProxyConfiguration.builder()
.host("proxy.example.com")
.port(8080)
.username("foo")
.password("bar")
.build())
.skipSslValidation(true)
.build();

assertThat(ctx.getConnectionPoolSize()).isEqualTo(24);
assertThat(ctx.getApiHost()).isEqualTo("api.example.com");
assertThat(ctx.getSkipSslValidation()).isEqualTo(Optional.of(true));

HttpClient client = ctx.getHttpClient();
assertThat(client.configuration().isSecure()).isEqualTo(true);

InetSocketAddress addr = client.configuration().proxyProvider().getAddress().get();
assertThat(addr.getHostName()).isEqualTo("proxy.example.com");
assertThat(addr.getPort()).isEqualTo(8080);
assertThat(client.configuration().proxyProvider().getType()).isEqualTo(ProxyProvider.Proxy.HTTP);

assertThat(client.configuration().loggingHandler().level()).isEqualTo(LogLevel.TRACE);
assertThat(client.configuration().loggingHandler().byteBufFormat()).isEqualTo(ByteBufFormat.HEX_DUMP);
}

}

0 comments on commit 7a2d445

Please sign in to comment.