From acd4729193d96976f42b6edc1de28f417d1de778 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Mon, 11 Nov 2024 11:28:57 +0300 Subject: [PATCH] Read whole object payload Signed-off-by: Alex Vanin --- api/handler/put.go | 16 ++++++++++++++++ api/layer/object.go | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/api/handler/put.go b/api/handler/put.go index 9e5a06a8..a5b7f930 100644 --- a/api/handler/put.go +++ b/api/handler/put.go @@ -191,6 +191,14 @@ func (h *handler) PutObjectHandler(w http.ResponseWriter, r *http.Request) { reqInfo = middleware.GetReqInfo(ctx) ) + payload, err := io.ReadAll(r.Body) + if err != nil { + h.logAndSendError(ctx, w, "could not read payload data", reqInfo, err) + return + } + + r.Body = io.NopCloser(bytes.NewReader(payload)) + bktInfo, err := h.getBucketAndCheckOwner(r, reqInfo.BucketName) if err != nil { h.logAndSendError(ctx, w, "could not get bucket objInfo", reqInfo, err) @@ -433,6 +441,14 @@ func (h *handler) PostObject(w http.ResponseWriter, r *http.Request) { metadata = make(map[string]string) ) + payload, err := io.ReadAll(r.Body) + if err != nil { + h.logAndSendError(ctx, w, "could not read payload data", reqInfo, err) + return + } + + r.Body = io.NopCloser(bytes.NewReader(payload)) + policy, err := checkPostPolicy(r, reqInfo, metadata) if err != nil { h.logAndSendError(ctx, w, "failed check policy", reqInfo, err) diff --git a/api/layer/object.go b/api/layer/object.go index e1dc75f5..02912b6e 100644 --- a/api/layer/object.go +++ b/api/layer/object.go @@ -522,9 +522,9 @@ func (n *Layer) objectPutAndHash(ctx context.Context, prm frostfs.PrmObjectCreat hash.Write(buf) md5Hash.Write(buf) }) - if threshold := n.features.ThresholdMaxSizeForPut(); threshold > 0 { - prm.Payload = wrapReaderThreshold(prm.Payload, int(threshold)) - } + // if threshold := n.features.ThresholdMaxSizeForPut(); threshold > 0 { + // prm.Payload = wrapReaderThreshold(prm.Payload, int(threshold)) + // } res, err := n.frostFS.CreateObject(ctx, prm) if err != nil { if _, errDiscard := io.Copy(io.Discard, prm.Payload); errDiscard != nil {