Skip to content

Commit

Permalink
Start using options internally
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Sep 14, 2023
1 parent f6aa3f9 commit f505e6d
Show file tree
Hide file tree
Showing 14 changed files with 531 additions and 474 deletions.
108 changes: 108 additions & 0 deletions src/main/generated/io/vertx/core/net/ConnectOptionsConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package io.vertx.core.net;

import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.impl.JsonUtil;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.Base64;

/**
* Converter and mapper for {@link io.vertx.core.net.ConnectOptions}.
* NOTE: This class has been automatically generated from the {@link io.vertx.core.net.ConnectOptions} original class using Vert.x codegen.
*/
public class ConnectOptionsConverter {


private static final Base64.Decoder BASE64_DECODER = JsonUtil.BASE64_DECODER;
private static final Base64.Encoder BASE64_ENCODER = JsonUtil.BASE64_ENCODER;

static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, ConnectOptions obj) {
for (java.util.Map.Entry<String, Object> member : json) {
switch (member.getKey()) {
case "applicationLayerProtocols":
if (member.getValue() instanceof JsonArray) {
java.util.ArrayList<java.lang.String> list = new java.util.ArrayList<>();
((Iterable<Object>)member.getValue()).forEach( item -> {
if (item instanceof String)
list.add((String)item);
});
obj.setApplicationLayerProtocols(list);
}
break;
case "host":
if (member.getValue() instanceof String) {
obj.setHost((String)member.getValue());
}
break;
case "hostnameVerificationAlgorithm":
if (member.getValue() instanceof String) {
obj.setHostnameVerificationAlgorithm((String)member.getValue());
}
break;
case "port":
if (member.getValue() instanceof Number) {
obj.setPort(((Number)member.getValue()).intValue());
}
break;
case "proxyOptions":
if (member.getValue() instanceof JsonObject) {
obj.setProxyOptions(new io.vertx.core.net.ProxyOptions((io.vertx.core.json.JsonObject)member.getValue()));
}
break;
case "sniServerName":
if (member.getValue() instanceof String) {
obj.setSniServerName((String)member.getValue());
}
break;
case "ssl":
if (member.getValue() instanceof Boolean) {
obj.setSsl((Boolean)member.getValue());
}
break;
case "sslOptions":
if (member.getValue() instanceof JsonObject) {
obj.setSslOptions(new io.vertx.core.net.SSLOptions((io.vertx.core.json.JsonObject)member.getValue()));
}
break;
case "trustAll":
if (member.getValue() instanceof Boolean) {
obj.setTrustAll((Boolean)member.getValue());
}
break;
}
}
}

static void toJson(ConnectOptions obj, JsonObject json) {
toJson(obj, json.getMap());
}

static void toJson(ConnectOptions obj, java.util.Map<String, Object> json) {
if (obj.getApplicationLayerProtocols() != null) {
JsonArray array = new JsonArray();
obj.getApplicationLayerProtocols().forEach(item -> array.add(item));
json.put("applicationLayerProtocols", array);
}
if (obj.getHost() != null) {
json.put("host", obj.getHost());
}
if (obj.getHostnameVerificationAlgorithm() != null) {
json.put("hostnameVerificationAlgorithm", obj.getHostnameVerificationAlgorithm());
}
if (obj.getPort() != null) {
json.put("port", obj.getPort());
}
if (obj.getProxyOptions() != null) {
json.put("proxyOptions", obj.getProxyOptions().toJson());
}
if (obj.getSniServerName() != null) {
json.put("sniServerName", obj.getSniServerName());
}
json.put("ssl", obj.isSsl());
if (obj.getSslOptions() != null) {
json.put("sslOptions", obj.getSslOptions().toJson());
}
json.put("trustAll", obj.isTrustAll());
}
}
22 changes: 18 additions & 4 deletions src/main/java/io/vertx/core/http/impl/HttpChannelConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
import io.vertx.core.impl.EventLoopContext;
import io.vertx.core.impl.ContextInternal;
import io.vertx.core.impl.future.PromiseInternal;
import io.vertx.core.net.NetSocket;
import io.vertx.core.net.ProxyOptions;
import io.vertx.core.net.SocketAddress;
import io.vertx.core.net.*;
import io.vertx.core.net.impl.NetClientInternal;
import io.vertx.core.net.impl.NetSocketImpl;
import io.vertx.core.net.impl.VertxHandler;
Expand Down Expand Up @@ -85,7 +83,23 @@ public SocketAddress server() {
}

private void connect(EventLoopContext context, Promise<NetSocket> promise) {
netClient.connectInternal(proxyOptions, server, peerAddress, this.options.isForceSni() ? peerAddress.host() : null, ssl, useAlpn, false, promise, context, 0);
ConnectOptions co = new ConnectOptions();
co.setServer(server);
if (peerAddress != null) {
co.setHost(peerAddress.host());
co.setPort(peerAddress.port());
if (options.isForceSni()) {
co.setSniServerName(peerAddress.hostName());
}
}
co.setSsl(ssl);
co.setHostnameVerificationAlgorithm(options.isVerifyHost() ? "HTTPS": null);
co.setProxyOptions(proxyOptions);
co.setSslOptions(new SSLOptions(client.sslOptions)
.setUseAlpn(useAlpn)
);

netClient.connectInternal(co, promise, context);
}

public Future<HttpClientConnection> wrap(EventLoopContext context, NetSocket so_) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/io/vertx/core/http/impl/HttpClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public class HttpClientImpl implements HttpClientInternal, MetricsProvider {
private Predicate<SocketAddress> proxyFilter;
private volatile Handler<HttpConnection> connectionHandler;
private volatile Function<HttpClientResponse, Future<RequestOptions>> redirectHandler = DEFAULT_HANDLER;
volatile SSLOptions sslOptions;
private final Function<ContextInternal, EventLoopContext> contextProvider;

public HttpClientImpl(VertxInternal vertx, HttpClientOptions options) {
Expand All @@ -150,6 +151,7 @@ public HttpClientImpl(VertxInternal vertx, HttpClientOptions options) {
break;
}
}
this.sslOptions = options.getSslOptions();
this.keepAlive = options.isKeepAlive();
this.pipelining = options.isPipelining();
if (!keepAlive && pipelining) {
Expand Down Expand Up @@ -501,7 +503,9 @@ public Metrics getMetrics() {

@Override
public Future<Void> updateSSLOptions(SSLOptions options) {
return netClient.updateSSLOptions(options);
// Todo should validate first ???
sslOptions = options;
return Future.succeededFuture();
}

@Override
Expand Down
Loading

0 comments on commit f505e6d

Please sign in to comment.