Skip to content

Commit

Permalink
Implementation of an HTTP client connection API.
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Jan 15, 2024
1 parent 496a905 commit bbc1f33
Show file tree
Hide file tree
Showing 28 changed files with 675 additions and 404 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package io.vertx.core.http;

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.http.HttpConnectOptions}.
* NOTE: This class has been automatically generated from the {@link io.vertx.core.http.HttpConnectOptions} original class using Vert.x codegen.
*/
public class HttpConnectOptionsConverter {


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, HttpConnectOptions obj) {
for (java.util.Map.Entry<String, Object> member : json) {
switch (member.getKey()) {
case "proxyOptions":
if (member.getValue() instanceof JsonObject) {
obj.setProxyOptions(new io.vertx.core.net.ProxyOptions((io.vertx.core.json.JsonObject)member.getValue()));
}
break;
case "host":
if (member.getValue() instanceof String) {
obj.setHost((String)member.getValue());
}
break;
case "port":
if (member.getValue() instanceof Number) {
obj.setPort(((Number)member.getValue()).intValue());
}
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.ClientSSLOptions((io.vertx.core.json.JsonObject)member.getValue()));
}
break;
case "connectTimeout":
if (member.getValue() instanceof Number) {
obj.setConnectTimeout(((Number)member.getValue()).longValue());
}
break;
}
}
}

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

static void toJson(HttpConnectOptions obj, java.util.Map<String, Object> json) {
if (obj.getProxyOptions() != null) {
json.put("proxyOptions", obj.getProxyOptions().toJson());
}
if (obj.getHost() != null) {
json.put("host", obj.getHost());
}
if (obj.getPort() != null) {
json.put("port", obj.getPort());
}
if (obj.isSsl() != null) {
json.put("ssl", obj.isSsl());
}
if (obj.getSslOptions() != null) {
json.put("sslOptions", obj.getSslOptions().toJson());
}
json.put("connectTimeout", obj.getConnectTimeout());
}
}
46 changes: 0 additions & 46 deletions src/main/generated/io/vertx/core/http/RequestOptionsConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,6 @@ public class RequestOptionsConverter {
static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, RequestOptions obj) {
for (java.util.Map.Entry<String, Object> member : json) {
switch (member.getKey()) {
case "proxyOptions":
if (member.getValue() instanceof JsonObject) {
obj.setProxyOptions(new io.vertx.core.net.ProxyOptions((io.vertx.core.json.JsonObject)member.getValue()));
}
break;
case "host":
if (member.getValue() instanceof String) {
obj.setHost((String)member.getValue());
}
break;
case "port":
if (member.getValue() instanceof Number) {
obj.setPort(((Number)member.getValue()).intValue());
}
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.ClientSSLOptions((io.vertx.core.json.JsonObject)member.getValue()));
}
break;
case "uri":
if (member.getValue() instanceof String) {
obj.setURI((String)member.getValue());
Expand All @@ -60,11 +35,6 @@ static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, Request
obj.setTimeout(((Number)member.getValue()).longValue());
}
break;
case "connectTimeout":
if (member.getValue() instanceof Number) {
obj.setConnectTimeout(((Number)member.getValue()).longValue());
}
break;
case "idleTimeout":
if (member.getValue() instanceof Number) {
obj.setIdleTimeout(((Number)member.getValue()).longValue());
Expand All @@ -89,29 +59,13 @@ static void toJson(RequestOptions obj, JsonObject json) {
}

static void toJson(RequestOptions obj, java.util.Map<String, Object> json) {
if (obj.getProxyOptions() != null) {
json.put("proxyOptions", obj.getProxyOptions().toJson());
}
if (obj.getHost() != null) {
json.put("host", obj.getHost());
}
if (obj.getPort() != null) {
json.put("port", obj.getPort());
}
if (obj.isSsl() != null) {
json.put("ssl", obj.isSsl());
}
if (obj.getSslOptions() != null) {
json.put("sslOptions", obj.getSslOptions().toJson());
}
if (obj.getURI() != null) {
json.put("uri", obj.getURI());
}
if (obj.getFollowRedirects() != null) {
json.put("followRedirects", obj.getFollowRedirects());
}
json.put("timeout", obj.getTimeout());
json.put("connectTimeout", obj.getConnectTimeout());
json.put("idleTimeout", obj.getIdleTimeout());
if (obj.getTraceOperation() != null) {
json.put("traceOperation", obj.getTraceOperation());
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/io/vertx/core/http/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.Future;
import io.vertx.core.net.ClientSSLOptions;
import io.vertx.core.net.HostAndPort;
import io.vertx.core.net.SocketAddress;

import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -145,4 +147,12 @@ default Future<Boolean> updateSSLOptions(ClientSSLOptions options) {
* @return a future signaling the update success
*/
Future<Boolean> updateSSLOptions(ClientSSLOptions options, boolean force);

/**
* Connect to a remote HTTP server.
*
* @param options the server connect options
*/
Future<HttpClientConnection> connect(HttpConnectOptions options);

}
41 changes: 41 additions & 0 deletions src/main/java/io/vertx/core/http/HttpClientConnection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2011-2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*/
package io.vertx.core.http;

import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.Future;

/**
* Represents an HTTP client connection.
*
* @author <a href="mailto:[email protected]">Julien Viet</a>
*/
@VertxGen
public interface HttpClientConnection extends HttpConnection {

/**
* Like {@link #createRequest(RequestOptions)} but with null options.
*/
Future<HttpClientRequest> createRequest();

/**
* Create an HTTP request initialized with the specified request {@code options}
*
* This enqueues a request in the client connection queue, the resulting future is notified when the connection can satisfy
* the request.
*
* Pooled HTTP connection will return an error, since requests should be made against the pool instead the connection itself.
*
* @return a future notified with the created request
*/
Future<HttpClientRequest> createRequest(RequestOptions options);

}
2 changes: 1 addition & 1 deletion src/main/java/io/vertx/core/http/HttpClientRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ default boolean reset() {
* @return the {@link HttpConnection} associated with this request
*/
@CacheReturn
HttpConnection connection();
HttpClientConnection connection();

/**
* Write an HTTP/2 frame to the request, allowing to extend the HTTP/2 protocol.<p>
Expand Down
Loading

0 comments on commit bbc1f33

Please sign in to comment.