Skip to content

Commit f57d2e5

Browse files
committed
Restore support for port embedded in the hostname
1 parent 4b1bef2 commit f57d2e5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

edgegrid-signer-apache-http-client/src/main/java/com/akamai/edgegrid/signer/apachehttpclient/ApacheHttpClientEdgeGridRoutePlanner.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,18 @@ public ApacheHttpClientEdgeGridRoutePlanner(ClientCredentialProvider clientCrede
3232
public HttpRoute determineRoute(HttpHost host, HttpRequest request, HttpContext context) throws HttpException {
3333
try {
3434
ClientCredential clientCredential = binding.getClientCredentialProvider().getClientCredential(binding.map(request));
35-
HttpHost target = new HttpHost(clientCredential.getHost(), -1, "https");
35+
String hostname = clientCredential.getHost();
36+
int port = -1;
37+
final int pos = hostname.lastIndexOf(":");
38+
if (pos > 0) {
39+
try {
40+
port = Integer.parseInt(hostname.substring(pos + 1));
41+
} catch (NumberFormatException ex) {
42+
throw new IllegalArgumentException("Host contains invalid port number: " + hostname);
43+
}
44+
hostname = hostname.substring(0, pos);
45+
}
46+
HttpHost target = new HttpHost(hostname, port, "https");
3647
return super.determineRoute(target, request, context);
3748
} catch (NoMatchingCredentialException e) {
3849
throw new RuntimeException(e);

0 commit comments

Comments
 (0)