mirror of https://github.com/apache/jclouds.git
Add logic from JCLOUDS-1261 to the other 2 types of Aws4 signer.
This commit is contained in:
parent
9bf7c5da5a
commit
36b3dadf8c
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue