Skip to content

Commit

Permalink
fix: handle SSE in statObject() and have one source code.
Browse files Browse the repository at this point in the history
  • Loading branch information
balamurugana committed Jul 15, 2019
1 parent d094626 commit 56239c3
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions api/src/main/java/io/minio/MinioClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,19 @@ private String getText(XmlPullParser xpp) throws XmlPullParserException {
return null;
}

private void checkReadRequestSse(ServerSideEncryption sse) throws InvalidArgumentException {
if (sse == null) {
return;
}

if (sse.getType() != SSE_C) {
throw new InvalidArgumentException("only SSE_C is supported for all read requests.");
}

if (!this.baseUrl.isHttps()) {
throw new InvalidArgumentException("SSE_C operations must be performed over a secure connection.");
}
}

/**
* Executes GET method for given request parameters.
Expand Down Expand Up @@ -1482,12 +1495,7 @@ public ObjectStat statObject(String bucketName, String objectName)
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException,InvalidResponseException {
HttpResponse response = executeHead(bucketName, objectName);
ResponseHeader header = response.header();
Map<String,List<String>> httpHeaders = response.httpHeaders();
ObjectStat objectStat = new ObjectStat(bucketName, objectName, header, httpHeaders);

return objectStat;
return statObject(bucketName, objectName, null);
}

/**
Expand Down Expand Up @@ -1523,14 +1531,14 @@ public ObjectStat statObject(String bucketName, String objectName, ServerSideEnc
throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException,
InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException,
InternalException, InvalidArgumentException, InvalidResponseException {
if ((sse.getType() == ServerSideEncryption.Type.SSE_S3)
|| (sse.getType() == ServerSideEncryption.Type.SSE_KMS)) {
throw new InvalidArgumentException("Invalid encryption option specified for encryption type " + sse.getType());
} else if ((sse.getType() == ServerSideEncryption.Type.SSE_C) && (!this.baseUrl.isHttps())) {
throw new InvalidArgumentException("SSE_C operations must be performed over a secure connection.");
checkReadRequestSse(sse);

Map<String, String> headers;
if (sse != null) {
headers = new HashMap<>();
sse.marshal(headers);
}
Map<String, String> headers = new HashMap<>();
sse.marshal(headers);

HttpResponse response = executeHead(bucketName, objectName, headers);
ResponseHeader header = response.header();
Map<String,List<String>> httpHeaders = response.httpHeaders();
Expand Down

0 comments on commit 56239c3

Please sign in to comment.