Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save creating (and validating) a peer INET address if not required #4928

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Changes from all 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
24 changes: 16 additions & 8 deletions src/main/java/io/vertx/core/http/impl/HttpClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ public Function<HttpClientResponse, Future<RequestOptions>> redirectHandler() {
}

private void doRequest(RequestOptions request, PromiseInternal<HttpClientRequest> promise) {
String host = getHost(request);
int port = getPort(request);
final String host = getHost(request);
final int port = getPort(request);
SocketAddress server = request.getServer();
if (server == null) {
server = SocketAddress.inetSocketAddress(port, host);
Expand All @@ -285,11 +285,13 @@ private void doRequest(RequestOptions request, PromiseInternal<HttpClientRequest
checkClosed();
ProxyOptions proxyOptions = resolveProxyOptions(request.getProxyOptions(), server);

String peerHost = host;
if (peerHost.endsWith(".")) {
peerHost = peerHost.substring(0, peerHost.length() - 1);
final String peerHost;
if (host.charAt(host.length() - 1) == '.') {
peerHost = host.substring(0, host.length() - 1);
} else {
peerHost = host;
}
SocketAddress peerAddress = SocketAddress.inetSocketAddress(port, peerHost);
SocketAddress peerAddress = peerAddress(server, peerHost, port);

EndpointKey key;
if (proxyOptions != null && !useSSL && proxyOptions.getType() == ProxyType.HTTP) {
Expand All @@ -312,12 +314,18 @@ private void doRequest(RequestOptions request, PromiseInternal<HttpClientRequest
} else {
key = new EndpointKey(useSSL, proxyOptions, server, peerAddress);
}
doRequest(method, peerAddress, server, host, port, useSSL, requestURI, headers, request.getTraceOperation(), timeout, followRedirects, proxyOptions, key, promise);
doRequest(method, server, host, port, useSSL, requestURI, headers, request.getTraceOperation(), timeout, followRedirects, proxyOptions, key, promise);
}

private static SocketAddress peerAddress(SocketAddress remoteAddress, final String peerHost, int peerPort) {
if (remoteAddress.isInetSocket() && peerHost.equals(remoteAddress.host()) && peerPort == remoteAddress.port()) {
return remoteAddress;
}
return SocketAddress.inetSocketAddress(peerPort, peerHost);
}

private void doRequest(
HttpMethod method,
SocketAddress peerAddress,
SocketAddress server,
String host,
int port,
Expand Down
Loading