diff --git a/api/handler/list.go b/api/handler/list.go index 81b681a02..424359791 100644 --- a/api/handler/list.go +++ b/api/handler/list.go @@ -2,6 +2,7 @@ package handler import ( "encoding/xml" + "errors" "net/http" "strconv" "time" @@ -119,6 +120,12 @@ func (h *handler) listObjects(w http.ResponseWriter, r *http.Request) (*listObje zap.String("request_id", rid), zap.Error(err)) + var s3Err api.Error + if ok := errors.As(err, &s3Err); ok { + api.WriteErrorResponse(r.Context(), w, s3Err, r.URL) + return nil, nil, err + } + api.WriteErrorResponse(r.Context(), w, api.Error{ Code: api.GetAPIError(api.ErrBadRequest).Code, Description: err.Error(), @@ -287,7 +294,7 @@ func parseListObjectArgs(r *http.Request) (*listObjectsArgs, error) { if r.URL.Query().Get("max-keys") == "" { res.MaxKeys = maxObjectList - } else if res.MaxKeys, err = strconv.Atoi(r.URL.Query().Get("max-keys")); err != nil || res.MaxKeys <= 0 { + } else if res.MaxKeys, err = strconv.Atoi(r.URL.Query().Get("max-keys")); err != nil || res.MaxKeys < 0 { return nil, api.GetAPIError(api.ErrInvalidMaxKeys) } @@ -384,7 +391,7 @@ func parseListObjectVersionsRequest(r *http.Request) (*layer.ListObjectVersionsP if r.URL.Query().Get("max-keys") == "" { res.MaxKeys = maxObjectList - } else if res.MaxKeys, err = strconv.Atoi(r.URL.Query().Get("max-keys")); err != nil || res.MaxKeys <= 0 { + } else if res.MaxKeys, err = strconv.Atoi(r.URL.Query().Get("max-keys")); err != nil || res.MaxKeys < 0 { return nil, api.GetAPIError(api.ErrInvalidMaxKeys) } diff --git a/api/layer/layer.go b/api/layer/layer.go index 328dbea4d..45f047e97 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -227,6 +227,10 @@ func (n *layer) ListObjects(ctx context.Context, p *ListObjectsParams) (*ListObj uniqNames = make(map[string]bool) ) + if p.MaxKeys == 0 { + return &result, nil + } + if bkt, err = n.GetBucketInfo(ctx, p.Bucket); err != nil { return nil, err } else if ids, err = n.objectSearch(ctx, &findParams{cid: bkt.CID}); err != nil {