JCLOUDS-766: Check metadata and headers for MD5

Addresses AWSS3ClientLiveTest.testMultipartSynchronously test
failures.
This commit is contained in:
Andrew Gaul 2016-03-18 22:55:34 -07:00
parent 35c5d7ffc0
commit 8053abb530
2 changed files with 12 additions and 6 deletions

View File

@ -106,14 +106,17 @@ public class Aws4SignerForAuthorizationHeader extends Aws4SignerBase {
}
// Content MD5
String contentMD5 = request.getFirstHeaderOrNull(CONTENT_MD5);
if (payload != null) {
HashCode md5 = payload.getContentMetadata().getContentMD5AsHashCode();
if (md5 != null) {
String contentMD5 = BaseEncoding.base64().encode(md5.asBytes());
requestBuilder.replaceHeader(CONTENT_MD5, contentMD5);
signedHeadersBuilder.put(CONTENT_MD5.toLowerCase(), contentMD5);
contentMD5 = BaseEncoding.base64().encode(md5.asBytes());
}
}
if (contentMD5 != null) {
requestBuilder.replaceHeader(CONTENT_MD5, contentMD5);
signedHeadersBuilder.put(CONTENT_MD5.toLowerCase(), contentMD5);
}
// host
requestBuilder.replaceHeader(HttpHeaders.HOST, host);

View File

@ -127,14 +127,17 @@ public class Aws4SignerForChunkedUpload extends Aws4SignerBase {
signedHeadersBuilder.put(CONTENT_LENGTH.toLowerCase(), Long.toString(totalLength));
// Content MD5
String contentMD5 = request.getFirstHeaderOrNull(CONTENT_MD5);
if (payload != null) {
HashCode md5 = payload.getContentMetadata().getContentMD5AsHashCode();
if (md5 != null) {
String contentMD5 = BaseEncoding.base64().encode(md5.asBytes());
requestBuilder.replaceHeader(CONTENT_MD5, contentMD5);
signedHeadersBuilder.put(CONTENT_MD5.toLowerCase(), contentMD5);
contentMD5 = BaseEncoding.base64().encode(md5.asBytes());
}
}
if (contentMD5 != null) {
requestBuilder.replaceHeader(CONTENT_MD5, contentMD5);
signedHeadersBuilder.put(CONTENT_MD5.toLowerCase(), contentMD5);
}
// Content Type
// content-type is not a required signing param. However, examples use this, so we include it to ease testing.