Resolves JCLOUDS-1261 by ensuring non-standard port numbers are in the host header that's used for the AWSv4 auth calculations.

This commit is contained in:
Stephen Tomkinson 2017-05-09 16:28:00 +01:00 committed by Andrew Gaul
parent 5b2aca103e
commit 15d27da739
1 changed files with 9 additions and 1 deletions

View File

@ -73,8 +73,9 @@ public class Aws4SignerForAuthorizationHeader extends Aws4SignerBase {
Payload payload = request.getPayload();
// get host from request endpoint.
// get host & port from request endpoint.
String host = request.getEndpoint().getHost();
int port = request.getEndpoint().getPort();
Date date = timestampProvider.get();
String timestamp = timestampFormat.format(date);
@ -119,6 +120,13 @@ public class Aws4SignerForAuthorizationHeader extends Aws4SignerBase {
}
// host
// if the port is defined and doesn't match the URI scheme
if (port != -1) {
if (("http".equalsIgnoreCase(request.getEndpoint().getScheme()) && port != 80) ||
("https".equalsIgnoreCase(request.getEndpoint().getScheme()) && port != 443)) {
host += ":" + port; // append the port number to the hostname
}
}
requestBuilder.replaceHeader(HttpHeaders.HOST, host);
signedHeadersBuilder.put(HttpHeaders.HOST.toLowerCase(), host);