From f6d8271e5d0b85da7c19104a83fef5d84d3a6ff6 Mon Sep 17 00:00:00 2001 From: Pavel Pogodaev Date: Thu, 5 Sep 2024 10:47:05 +0300 Subject: [PATCH] [#450] Fix aws-chunked header workflow Signed-off-by: Pavel Pogodaev --- api/handler/multipart_upload.go | 5 +---- api/handler/put.go | 5 +---- api/handler/util.go | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/api/handler/multipart_upload.go b/api/handler/multipart_upload.go index d0a42fb..b1d5d4f 100644 --- a/api/handler/multipart_upload.go +++ b/api/handler/multipart_upload.go @@ -203,10 +203,7 @@ func (h *handler) UploadPartHandler(w http.ResponseWriter, r *http.Request) { return } - var size uint64 - if r.ContentLength > 0 { - size = uint64(r.ContentLength) - } + size := h.getPutPayloadSize(r) p := &layer.UploadPartParams{ Info: &layer.UploadInfoParams{ diff --git a/api/handler/put.go b/api/handler/put.go index 94cc0f3..4000f53 100644 --- a/api/handler/put.go +++ b/api/handler/put.go @@ -241,10 +241,7 @@ func (h *handler) PutObjectHandler(w http.ResponseWriter, r *http.Request) { metadata[api.ContentEncoding] = encodings } - var size uint64 - if r.ContentLength > 0 { - size = uint64(r.ContentLength) - } + size := h.getPutPayloadSize(r) params := &layer.PutObjectParams{ BktInfo: bktInfo, diff --git a/api/handler/util.go b/api/handler/util.go index dde5274..3665488 100644 --- a/api/handler/util.go +++ b/api/handler/util.go @@ -106,6 +106,23 @@ func (h *handler) getBucketAndCheckOwner(r *http.Request, bucket string, header return bktInfo, checkOwner(bktInfo, expected) } +func (h *handler) getPutPayloadSize(r *http.Request) uint64 { + decodeContentSize := r.Header.Get(api.AmzDecodedContentLength) + decodedSize, err := strconv.Atoi(decodeContentSize) + if err != nil { + decodedSize = 0 + } + + var size uint64 + if decodedSize > 0 { + size = uint64(decodedSize) + } else if r.ContentLength > 0 { + size = uint64(r.ContentLength) + } + + return size +} + func parseRange(s string) (*layer.RangeParams, error) { if s == "" { return nil, nil