-
Notifications
You must be signed in to change notification settings - Fork 945
Make ApacheHttpClient5Request public #12394
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -7,28 +7,19 @@ | |||
|
||||
import static java.util.logging.Level.FINE; | ||||
|
||||
import java.net.InetAddress; | ||||
import java.net.InetSocketAddress; | ||||
import java.net.URI; | ||||
import java.net.URISyntaxException; | ||||
import java.util.ArrayList; | ||||
import java.util.Collections; | ||||
import java.util.List; | ||||
import java.util.logging.Logger; | ||||
import javax.annotation.Nullable; | ||||
import org.apache.hc.core5.http.Header; | ||||
import org.apache.hc.core5.http.HttpHost; | ||||
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()); | ||||
|
||||
@Nullable private final URI uri; | ||||
|
||||
private final HttpRequest delegate; | ||||
@Nullable private final HttpHost target; | ||||
|
||||
ApacheHttpClient5Request(@Nullable HttpHost httpHost, HttpRequest httpRequest) { | ||||
URI calculatedUri = getUri(httpRequest); | ||||
|
@@ -38,34 +29,13 @@ final class ApacheHttpClient5Request { | |||
uri = calculatedUri; | ||||
} | ||||
delegate = httpRequest; | ||||
target = httpHost; | ||||
} | ||||
|
||||
/** Returns the actual {@link HttpRequest} being executed by the client. */ | ||||
public HttpRequest getDelegate() { | ||||
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() { | ||||
return delegate.getMethod(); | ||||
} | ||||
|
@@ -75,28 +45,6 @@ String getUrl() { | |||
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 | ||||
private static URI getUri(HttpRequest httpRequest) { | ||||
try { | ||||
|
@@ -124,13 +72,4 @@ private static URI getCalculatedUri(HttpHost httpHost, URI uri) { | |||
return null; | ||||
} | ||||
} | ||||
|
||||
@Nullable | ||||
public InetSocketAddress getServerSocketAddress() { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems many methods in this class was copied from other version modules, delete them together? such as Line 129 in d156afb
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this method is used in 4.3 instrumentation |
||||
if (target == null) { | ||||
return null; | ||||
} | ||||
InetAddress inetAddress = target.getAddress(); | ||||
return inetAddress == null ? null : new InetSocketAddress(inetAddress, target.getPort()); | ||||
} | ||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should perhaps add Javadoc?