From d9d80f7c22a32bc7b1b5120399a2b52cad98e0fc Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 23 Jan 2015 12:14:39 -0800 Subject: [PATCH] Get Bucket List objects compliance MaxKeys to 1000, Rename Content struct to Item for cosmetic reasons for xml decoding on client side --- pkg/webapi/minioapi/definitions.go | 10 +++++++--- pkg/webapi/minioapi/minioapi.go | 9 ++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pkg/webapi/minioapi/definitions.go b/pkg/webapi/minioapi/definitions.go index 6961fb40d..7b9a84a3d 100644 --- a/pkg/webapi/minioapi/definitions.go +++ b/pkg/webapi/minioapi/definitions.go @@ -20,13 +20,17 @@ import ( "encoding/xml" ) +const ( + MAX_OBJECT_LIST = 1000 +) + type ObjectListResponse struct { XMLName xml.Name `xml:"ListBucketResult"` - Name string `xml:"Name"` + Name string Marker string MaxKeys int IsTruncated bool - Contents []Content `xml:"Contents",innerxml` + Contents []*Item `xml:"Contents",innerxml` } type BucketListResponse struct { @@ -42,7 +46,7 @@ type Bucket struct { CreationDate string } -type Content struct { +type Item struct { Key string LastModified string ETag string diff --git a/pkg/webapi/minioapi/minioapi.go b/pkg/webapi/minioapi/minioapi.go index 325fc83b3..3b8c3d09d 100644 --- a/pkg/webapi/minioapi/minioapi.go +++ b/pkg/webapi/minioapi/minioapi.go @@ -157,7 +157,6 @@ func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Requ } contentType := "xml" - if _, ok := req.Header["Accept"]; ok { if req.Header["Accept"][0] == "application/json" { contentType = "json" @@ -176,8 +175,8 @@ func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Requ w.Header().Set("Content-Type", `xml version="1.0" encoding="UTF-8"`) encoder = xml.NewEncoder(&bytesBuffer) } - encoder.Encode(response) + encoder.Encode(response) w.Write(bytesBuffer.Bytes()) } @@ -228,7 +227,7 @@ func generateBucketsListResult(buckets []mstorage.BucketMetadata) (data BucketLi } func generateObjectsListResult(bucket string, objects []mstorage.ObjectMetadata) (data ObjectListResponse) { - contents := []Content{} + var contents []*Item owner := Owner{ ID: "minio", @@ -236,7 +235,7 @@ func generateObjectsListResult(bucket string, objects []mstorage.ObjectMetadata) } for _, object := range objects { - content := Content{ + content := &Item{ Key: object.Key, LastModified: formatDate(object.Created), ETag: object.ETag, @@ -249,7 +248,7 @@ func generateObjectsListResult(bucket string, objects []mstorage.ObjectMetadata) data = ObjectListResponse{ Name: bucket, Contents: contents, - MaxKeys: len(objects), + MaxKeys: MAX_OBJECT_LIST, IsTruncated: false, } return