diff --git a/cmd/api-headers.go b/cmd/api-headers.go index 4d0dabfd4..a9b8031d0 100644 --- a/cmd/api-headers.go +++ b/cmd/api-headers.go @@ -68,6 +68,13 @@ func encodeResponseJSON(response interface{}) []byte { return bytesBuffer.Bytes() } +// Write parts count +func setPartsCountHeaders(w http.ResponseWriter, objInfo ObjectInfo) { + if strings.Contains(objInfo.ETag, "-") && len(objInfo.Parts) > 0 { + w.Header()[xhttp.AmzMpPartsCount] = []string{strconv.Itoa(len(objInfo.Parts))} + } +} + // Write object header func setObjectHeaders(w http.ResponseWriter, objInfo ObjectInfo, rs *HTTPRangeSpec) (err error) { // set common headers @@ -82,10 +89,6 @@ func setObjectHeaders(w http.ResponseWriter, objInfo ObjectInfo, rs *HTTPRangeSp w.Header()[xhttp.ETag] = []string{"\"" + objInfo.ETag + "\""} } - if strings.Contains(objInfo.ETag, "-") && len(objInfo.Parts) > 0 { - w.Header()[xhttp.AmzMpPartsCount] = []string{strconv.Itoa(len(objInfo.Parts))} - } - if objInfo.ContentType != "" { w.Header().Set(xhttp.ContentType, objInfo.ContentType) } diff --git a/cmd/encryption-v1.go b/cmd/encryption-v1.go index d71a77583..789f40e5e 100644 --- a/cmd/encryption-v1.go +++ b/cmd/encryption-v1.go @@ -903,7 +903,7 @@ func getOpts(ctx context.Context, r *http.Request, bucket, object string) (Objec if err != nil { return opts, err } - if partNumber < 0 { + if partNumber <= 0 { return opts, errInvalidArgument } } diff --git a/cmd/object-handlers-common.go b/cmd/object-handlers-common.go index 6d9bff9ec..9d7ecb1b7 100644 --- a/cmd/object-handlers-common.go +++ b/cmd/object-handlers-common.go @@ -173,9 +173,9 @@ func checkPreconditions(ctx context.Context, w http.ResponseWriter, r *http.Requ } // Check if the part number is correct. - if opts.PartNumber > 0 && len(objInfo.Parts) > 0 && opts.PartNumber != len(objInfo.Parts) { + if opts.PartNumber > 1 && opts.PartNumber > len(objInfo.Parts) { writeHeaders() - writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrPreconditionFailed), r.URL, guessIsBrowserReq(r)) + w.WriteHeader(http.StatusRequestedRangeNotSatisfiable) return true } diff --git a/cmd/object-handlers.go b/cmd/object-handlers.go index c38c3a962..7ae90aef1 100644 --- a/cmd/object-handlers.go +++ b/cmd/object-handlers.go @@ -426,6 +426,11 @@ func (api objectAPIHandlers) GetObjectHandler(w http.ResponseWriter, r *http.Req return } + // Set Parts Count Header + if opts.PartNumber > 0 && len(objInfo.Parts) > 0 { + setPartsCountHeaders(w, objInfo) + } + setHeadGetRespHeaders(w, r.URL.Query()) setAmzExpirationHeader(w, bucket, objInfo) @@ -604,6 +609,11 @@ func (api objectAPIHandlers) HeadObjectHandler(w http.ResponseWriter, r *http.Re return } + // Set Parts Count Header + if opts.PartNumber > 0 && len(objInfo.Parts) > 0 { + setPartsCountHeaders(w, objInfo) + } + // Set any additional requested response headers. setHeadGetRespHeaders(w, r.URL.Query()) diff --git a/cmd/web-handlers.go b/cmd/web-handlers.go index 4da5cf04c..8f6f0c968 100644 --- a/cmd/web-handlers.go +++ b/cmd/web-handlers.go @@ -1310,6 +1310,11 @@ func (web *webAPIHandlers) Download(w http.ResponseWriter, r *http.Request) { } } + // Set Parts Count Header + if opts.PartNumber > 0 && len(objInfo.Parts) > 0 { + setPartsCountHeaders(w, objInfo) + } + if err = setObjectHeaders(w, objInfo, nil); err != nil { writeWebErrorResponse(w, err) return