Make ApacheHttpClient5Request public (#12394)

This commit is contained in:
Lauri Tulmin 2024-10-07 16:05:06 +03:00 committed by GitHub
parent e90959b20c
commit 8b4979f949
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 1 additions and 62 deletions

View File

@ -7,28 +7,19 @@ package io.opentelemetry.instrumentation.apachehttpclient.v5_2;
import static java.util.logging.Level.FINE; import static java.util.logging.Level.FINE;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpHost; import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpRequest; import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.ProtocolVersion;
final class ApacheHttpClient5Request { public final class ApacheHttpClient5Request {
private static final Logger logger = Logger.getLogger(ApacheHttpClient5Request.class.getName()); private static final Logger logger = Logger.getLogger(ApacheHttpClient5Request.class.getName());
@Nullable private final URI uri; @Nullable private final URI uri;
private final HttpRequest delegate; private final HttpRequest delegate;
@Nullable private final HttpHost target;
ApacheHttpClient5Request(@Nullable HttpHost httpHost, HttpRequest httpRequest) { ApacheHttpClient5Request(@Nullable HttpHost httpHost, HttpRequest httpRequest) {
URI calculatedUri = getUri(httpRequest); URI calculatedUri = getUri(httpRequest);
@ -38,7 +29,6 @@ final class ApacheHttpClient5Request {
uri = calculatedUri; uri = calculatedUri;
} }
delegate = httpRequest; delegate = httpRequest;
target = httpHost;
} }
/** Returns the actual {@link HttpRequest} being executed by the client. */ /** Returns the actual {@link HttpRequest} being executed by the client. */
@ -46,26 +36,6 @@ final class ApacheHttpClient5Request {
return delegate; return delegate;
} }
List<String> getHeader(String name) {
return headersToList(delegate.getHeaders(name));
}
// minimize memory overhead by not using streams
static List<String> headersToList(Header[] headers) {
if (headers.length == 0) {
return Collections.emptyList();
}
List<String> headersList = new ArrayList<>(headers.length);
for (Header header : headers) {
headersList.add(header.getValue());
}
return headersList;
}
void setHeader(String name, String value) {
delegate.setHeader(name, value);
}
String getMethod() { String getMethod() {
return delegate.getMethod(); return delegate.getMethod();
} }
@ -75,28 +45,6 @@ final class ApacheHttpClient5Request {
return uri != null ? uri.toString() : null; return uri != null ? uri.toString() : null;
} }
String getProtocolName() {
return delegate.getVersion().getProtocol();
}
String getProtocolVersion() {
ProtocolVersion protocolVersion = delegate.getVersion();
if (protocolVersion.getMinor() == 0) {
return Integer.toString(protocolVersion.getMajor());
}
return protocolVersion.getMajor() + "." + protocolVersion.getMinor();
}
@Nullable
public String getServerAddress() {
return uri == null ? null : uri.getHost();
}
@Nullable
public Integer getServerPort() {
return uri == null ? null : uri.getPort();
}
@Nullable @Nullable
private static URI getUri(HttpRequest httpRequest) { private static URI getUri(HttpRequest httpRequest) {
try { try {
@ -124,13 +72,4 @@ final class ApacheHttpClient5Request {
return null; return null;
} }
} }
@Nullable
public InetSocketAddress getServerSocketAddress() {
if (target == null) {
return null;
}
InetAddress inetAddress = target.getAddress();
return inetAddress == null ? null : new InetSocketAddress(inetAddress, target.getPort());
}
} }