From 98815d5473bfbeea9c632db27b8ad2c8232e5e9a 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 1795c29..17c592d 100644 --- a/api/handler/multipart_upload.go +++ b/api/handler/multipart_upload.go @@ -205,10 +205,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 e740cbb..59c1499 100644 --- a/api/handler/put.go +++ b/api/handler/put.go @@ -242,10 +242,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