Add logic from JCLOUDS-1261 to the other 2 types of Aws4 signer.

This commit is contained in:
Stephen Tomkinson 2017-05-10 11:41:23 +01:00 committed by Andrew Gaul
parent 6452960c72
commit 89ae3b4fa6
4 changed files with 19 additions and 8 deletions

View File

@ -133,6 +133,22 @@ public abstract class Aws4SignerBase {
dateFormat.setTimeZone(GMT);
}
protected static String hostHeaderFor(URI endpoint) {
String scheme = endpoint.getScheme();
String host = endpoint.getHost();
int port = endpoint.getPort();
// if the port is defined and doesn't match the URI scheme
if (port != -1) {
if (("http".equalsIgnoreCase(scheme) && port != 80) ||
("https".equalsIgnoreCase(scheme) && port != 443)) {
host += ":" + port; // append the port number to the hostname
}
}
return host; // else just use the original hostname
}
protected String getContentType(HttpRequest request) {
Payload payload = request.getPayload();

View File

@ -75,7 +75,6 @@ public class Aws4SignerForAuthorizationHeader extends Aws4SignerBase {
// 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);
@ -120,13 +119,7 @@ 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
}
}
host = hostHeaderFor(request.getEndpoint());
requestBuilder.replaceHeader(HttpHeaders.HOST, host);
signedHeadersBuilder.put(HttpHeaders.HOST.toLowerCase(), host);

View File

@ -155,6 +155,7 @@ public class Aws4SignerForChunkedUpload extends Aws4SignerBase {
}
// host
host = hostHeaderFor(request.getEndpoint());
requestBuilder.replaceHeader(HttpHeaders.HOST, host);
signedHeadersBuilder.put(HttpHeaders.HOST.toLowerCase(), host);

View File

@ -102,6 +102,7 @@ public class Aws4SignerForQueryString extends Aws4SignerBase {
// For added security, you should sign as many headers as possible.
// HOST
host = hostHeaderFor(request.getEndpoint());
signedHeadersBuilder.put("host", host);
ImmutableMap<String, String> signedHeaders = signedHeadersBuilder.build();