Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#### Dependency Upgrade

#### New Features
* Fix #7252: Allow VertxHttpClientBuilder to be seeded with a base WebClientOptions object, allowing more customization of the Vertx HTTP Client

#### _**Note**_: Breaking changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class VertxHttpClientBuilder<F extends HttpClient.Factory>

final Vertx vertx;
private final boolean closeVertx;
private WebClientOptions customWebClientOptions;

public VertxHttpClientBuilder(F clientFactory, Vertx sharedVertx) {
this(
Expand All @@ -64,13 +65,31 @@ public VertxHttpClientBuilder(F clientFactory, Vertx sharedVertx) {
this.closeVertx = closeVertx;
}

/**
* Use the provided {@link WebClientOptions} as the base options for the client.
* <p>
* Note: The Builder overrides some options to ensure the client works properly with the Kubernetes API server.
* These options that the Builder controls will override the values you set in the provided
* {@link WebClientOptions}.
* </p>
*/
public VertxHttpClientBuilder<F> withCustomWebClientOptions(WebClientOptions options) {
this.customWebClientOptions = options;
return this;
}

@Override
public VertxHttpClient<F> build() {
if (this.client != null) {
return new VertxHttpClient<>(this, this.client.getClosed(), this.client.getClient(), closeVertx);
}

WebClientOptions options = new WebClientOptions();
WebClientOptions options;
if (customWebClientOptions == null) {
options = new WebClientOptions();
} else {
options = new WebClientOptions(customWebClientOptions);
}

options.setMaxPoolSize(MAX_CONNECTIONS);
options.setMaxWebSockets(MAX_CONNECTIONS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.fabric8.kubernetes.client.http.HttpClient;
import io.vertx.core.Vertx;
import io.vertx.core.impl.VertxImpl;
import io.vertx.ext.web.client.WebClientOptions;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -81,4 +82,24 @@ void closesVertxInstanceWhenClientIsClosed() {
.asInstanceOf(InstanceOfAssertFactories.type(VertxImpl.class))
.returns(true, vi -> vi.closeFuture().isClosed());
}

@Test
void buildsSuccessfullyWithCustomWebClientOptions() {
WebClientOptions customOptions = new WebClientOptions()
.setKeepAlive(false)
.setTcpNoDelay(false)
.setUserAgent("custom-agent");

VertxHttpClientFactory factory = new VertxHttpClientFactory();
VertxHttpClientBuilder<?> builder = factory.newBuilder();

try (HttpClient client = builder.withCustomWebClientOptions(customOptions).build()) {
assertThat(client)
.isInstanceOf(VertxHttpClient.class)
.isNotNull();

assertThat(client.newHttpRequestBuilder().uri("http://localhost").build())
.isNotNull();
}
}
}