diff --git a/cmd/api-resources.go b/cmd/api-resources.go
index bc1cfb316..e485e3654 100644
--- a/cmd/api-resources.go
+++ b/cmd/api-resources.go
@@ -36,7 +36,7 @@ func getListObjectsV1Args(values url.Values) (prefix, marker, delimiter string,
}
// Parse bucket url queries for ListObjects V2.
-func getListObjectsV2Args(values url.Values) (prefix, token, startAfter, delimiter string, maxkeys int, encodingType string) {
+func getListObjectsV2Args(values url.Values) (prefix, token, startAfter, delimiter string, fetchOwner bool, maxkeys int, encodingType string) {
prefix = values.Get("prefix")
startAfter = values.Get("start-after")
delimiter = values.Get("delimiter")
@@ -47,6 +47,9 @@ func getListObjectsV2Args(values url.Values) (prefix, token, startAfter, delimit
}
encodingType = values.Get("encoding-type")
token = values.Get("continuation-token")
+ if values.Get("fetch-owner") == "true" {
+ fetchOwner = true
+ }
return
}
diff --git a/cmd/api-response.go b/cmd/api-response.go
index a8c2e6cf9..68aa005cc 100644
--- a/cmd/api-response.go
+++ b/cmd/api-response.go
@@ -327,14 +327,16 @@ func generateListObjectsV1Response(bucket, prefix, marker, delimiter string, max
}
// generates an ListObjectsV2 response for the said bucket with other enumerated options.
-func generateListObjectsV2Response(bucket, prefix, token, startAfter, delimiter string, maxKeys int, resp ListObjectsInfo) ListObjectsV2Response {
+func generateListObjectsV2Response(bucket, prefix, token, startAfter, delimiter string, fetchOwner bool, maxKeys int, resp ListObjectsInfo) ListObjectsV2Response {
var contents []Object
var prefixes []CommonPrefix
var owner = Owner{}
var data = ListObjectsV2Response{}
- owner.ID = "minio"
- owner.DisplayName = "minio"
+ if fetchOwner {
+ owner.ID = "minio"
+ owner.DisplayName = "minio"
+ }
for _, object := range resp.Objects {
var content = Object{}
diff --git a/cmd/bucket-handlers-listobjects.go b/cmd/bucket-handlers-listobjects.go
index c4405c384..dd406e711 100644
--- a/cmd/bucket-handlers-listobjects.go
+++ b/cmd/bucket-handlers-listobjects.go
@@ -82,7 +82,7 @@ func (api objectAPIHandlers) ListObjectsV2Handler(w http.ResponseWriter, r *http
}
}
// Extract all the listObjectsV2 query params to their native values.
- prefix, token, startAfter, delimiter, maxKeys, _ := getListObjectsV2Args(r.URL.Query())
+ prefix, token, startAfter, delimiter, fetchOwner, maxKeys, _ := getListObjectsV2Args(r.URL.Query())
// In ListObjectsV2 'continuation-token' is the marker.
marker := token
@@ -91,7 +91,8 @@ func (api objectAPIHandlers) ListObjectsV2Handler(w http.ResponseWriter, r *http
// Then we need to use 'start-after' as marker instead.
marker = startAfter
}
- // Validate all the query params before beginning to serve the request.
+ // Validate the query params before beginning to serve the request.
+ // fetch-owner is not validated since it is a boolean
if s3Error := listObjectsValidateArgs(prefix, marker, delimiter, maxKeys); s3Error != ErrNone {
writeErrorResponse(w, r, s3Error, r.URL.Path)
return
@@ -106,7 +107,7 @@ func (api objectAPIHandlers) ListObjectsV2Handler(w http.ResponseWriter, r *http
return
}
- response := generateListObjectsV2Response(bucket, prefix, token, startAfter, delimiter, maxKeys, listObjectsInfo)
+ response := generateListObjectsV2Response(bucket, prefix, token, startAfter, delimiter, fetchOwner, maxKeys, listObjectsInfo)
// Write headers
setCommonHeaders(w)
// Write success response.
diff --git a/cmd/server_test.go b/cmd/server_test.go
index 8e986932c..f7ac00b00 100644
--- a/cmd/server_test.go
+++ b/cmd/server_test.go
@@ -1367,7 +1367,7 @@ func (s *TestSuiteCommon) TestListObjectsHandler(c *C) {
c.Assert(strings.Contains(string(getContent), "bar"), Equals, true)
// create listObjectsV2 request with valid parameters
- request, err = newTestSignedRequest("GET", getListObjectsV2URL(s.endPoint, bucketName, "1000"),
+ request, err = newTestSignedRequest("GET", getListObjectsV2URL(s.endPoint, bucketName, "1000", ""),
0, nil, s.accessKey, s.secretKey)
c.Assert(err, IsNil)
client = http.Client{}
@@ -1378,6 +1378,22 @@ func (s *TestSuiteCommon) TestListObjectsHandler(c *C) {
getContent, err = ioutil.ReadAll(response.Body)
c.Assert(strings.Contains(string(getContent), "bar"), Equals, true)
+ c.Assert(strings.Contains(string(getContent), ""), Equals, true)
+
+ // create listObjectsV2 request with valid parameters and fetch-owner activated
+ request, err = newTestSignedRequest("GET", getListObjectsV2URL(s.endPoint, bucketName, "1000", "true"),
+ 0, nil, s.accessKey, s.secretKey)
+ c.Assert(err, IsNil)
+ client = http.Client{}
+ // execute the HTTP request.
+ response, err = client.Do(request)
+ c.Assert(err, IsNil)
+ c.Assert(response.StatusCode, Equals, http.StatusOK)
+
+ getContent, err = ioutil.ReadAll(response.Body)
+ c.Assert(strings.Contains(string(getContent), "bar"), Equals, true)
+ c.Assert(strings.Contains(string(getContent), "miniominio"), Equals, true)
+
}
// TestListObjectsHandlerErrors - Setting invalid parameters to List Objects
@@ -1408,7 +1424,7 @@ func (s *TestSuiteCommon) TestListObjectsHandlerErrors(c *C) {
verifyError(c, response, "InvalidArgument", "Argument maxKeys must be an integer between 0 and 2147483647", http.StatusBadRequest)
// create listObjectsV2 request with invalid value of max-keys parameter. max-keys is set to -2.
- request, err = newTestSignedRequest("GET", getListObjectsV2URL(s.endPoint, bucketName, "-2"),
+ request, err = newTestSignedRequest("GET", getListObjectsV2URL(s.endPoint, bucketName, "-2", ""),
0, nil, s.accessKey, s.secretKey)
c.Assert(err, IsNil)
client = http.Client{}
diff --git a/cmd/test-utils_test.go b/cmd/test-utils_test.go
index 2f20dae84..c538fd908 100644
--- a/cmd/test-utils_test.go
+++ b/cmd/test-utils_test.go
@@ -706,12 +706,15 @@ func getListObjectsV1URL(endPoint, bucketName string, maxKeys string) string {
}
// return URL for listing objects in the bucket with V2 API.
-func getListObjectsV2URL(endPoint, bucketName string, maxKeys string) string {
+func getListObjectsV2URL(endPoint, bucketName string, maxKeys string, fetchOwner string) string {
queryValue := url.Values{}
queryValue.Set("list-type", "2") // Enables list objects V2 URL.
if maxKeys != "" {
queryValue.Set("max-keys", maxKeys)
}
+ if fetchOwner != "" {
+ queryValue.Set("fetch-owner", fetchOwner)
+ }
return makeTestTargetURL(endPoint, bucketName, "", queryValue)
}