if(!validAscii) {
String message =
"User metadata name is incompatible with the S3 REST interface, " +
"only ASCII characters are allowed in HTTP headers: " + key;
if(encodingException == null) {
throw new ServiceException(message);
}
else {
throw new ServiceException(message, encodingException);
}
}
// Fail early if user-supplied metadata cannot be represented as valid HTTP headers,
// rather than waiting for a SignatureDoesNotMatch error.
// NOTE: These checks are very much incomplete.
if(value.indexOf('\n') >= 0 || value.indexOf('\r') >= 0) {
throw new ServiceException("The value of metadata item " + key
+ " cannot be represented as an HTTP header for the REST S3 interface: "
+ value);
}
// Ensure each AMZ header is uniquely identified according to the lowercase name.
String duplicateValue = (String) headersAlreadySeenMap.get(key.toLowerCase(Locale.ENGLISH));
if(duplicateValue != null && !duplicateValue.equals(value)) {
throw new ServiceException(
"HTTP header name occurs multiple times in request with different values, " +
"probably due to mismatched capitalization when setting metadata names. " +
"Duplicate metadata name: '" + key + "', All metadata: " + metadata);
}