[#450] Fix aws-chunked header workflow
Signed-off-by: Pavel Pogodaev <p.pogodaev@yadro.com>
This commit is contained in:
parent
9e1766ff74
commit
8f6ef17687
2 changed files with 18 additions and 12 deletions
|
@ -200,14 +200,16 @@ func (h *handler) UploadPartHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := h.getBodyReader(r)
|
body, decodedSize, err := h.getBodyReader(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.logAndSendError(w, "failed to get body reader", reqInfo, err, additional...)
|
h.logAndSendError(w, "failed to get body reader", reqInfo, err, additional...)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var size uint64
|
var size uint64
|
||||||
if r.ContentLength > 0 {
|
if decodedSize > 0 {
|
||||||
|
size = uint64(decodedSize)
|
||||||
|
} else if r.ContentLength > 0 {
|
||||||
size = uint64(r.ContentLength)
|
size = uint64(r.ContentLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -233,7 +233,7 @@ func (h *handler) PutObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := h.getBodyReader(r)
|
body, decodedSize, err := h.getBodyReader(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.logAndSendError(w, "failed to get body reader", reqInfo, err)
|
h.logAndSendError(w, "failed to get body reader", reqInfo, err)
|
||||||
return
|
return
|
||||||
|
@ -243,7 +243,10 @@ func (h *handler) PutObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var size uint64
|
var size uint64
|
||||||
if r.ContentLength > 0 {
|
|
||||||
|
if decodedSize > 0 {
|
||||||
|
size = uint64(decodedSize)
|
||||||
|
} else if r.ContentLength > 0 {
|
||||||
size = uint64(r.ContentLength)
|
size = uint64(r.ContentLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,9 +313,9 @@ func (h *handler) PutObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *handler) getBodyReader(r *http.Request) (io.ReadCloser, error) {
|
func (h *handler) getBodyReader(r *http.Request) (io.ReadCloser, int, error) {
|
||||||
if !api.IsSignedStreamingV4(r) {
|
if !api.IsSignedStreamingV4(r) {
|
||||||
return r.Body, nil
|
return r.Body, -1, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
encodings := r.Header.Values(api.ContentEncoding)
|
encodings := r.Header.Values(api.ContentEncoding)
|
||||||
|
@ -331,25 +334,26 @@ func (h *handler) getBodyReader(r *http.Request) (io.ReadCloser, error) {
|
||||||
r.Header.Set(api.ContentEncoding, strings.Join(resultContentEncoding, ","))
|
r.Header.Set(api.ContentEncoding, strings.Join(resultContentEncoding, ","))
|
||||||
|
|
||||||
if !chunkedEncoding && !h.cfg.BypassContentEncodingInChunks() {
|
if !chunkedEncoding && !h.cfg.BypassContentEncodingInChunks() {
|
||||||
return nil, fmt.Errorf("%w: request is not chunk encoded, encodings '%s'",
|
return nil, -1, fmt.Errorf("%w: request is not chunk encoded, encodings '%s'",
|
||||||
errors.GetAPIError(errors.ErrInvalidEncodingMethod), strings.Join(encodings, ","))
|
errors.GetAPIError(errors.ErrInvalidEncodingMethod), strings.Join(encodings, ","))
|
||||||
}
|
}
|
||||||
|
|
||||||
decodeContentSize := r.Header.Get(api.AmzDecodedContentLength)
|
decodeContentSize := r.Header.Get(api.AmzDecodedContentLength)
|
||||||
if len(decodeContentSize) == 0 {
|
if len(decodeContentSize) == 0 {
|
||||||
return nil, errors.GetAPIError(errors.ErrMissingContentLength)
|
return nil, -1, errors.GetAPIError(errors.ErrMissingContentLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := strconv.Atoi(decodeContentSize); err != nil {
|
decoded, err := strconv.Atoi(decodeContentSize)
|
||||||
return nil, fmt.Errorf("%w: parse decoded content length: %s", errors.GetAPIError(errors.ErrMissingContentLength), err.Error())
|
if err != nil {
|
||||||
|
return nil, -1, fmt.Errorf("%w: parse decoded content length: %s", errors.GetAPIError(errors.ErrMissingContentLength), err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
chunkReader, err := newSignV4ChunkedReader(r)
|
chunkReader, err := newSignV4ChunkedReader(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("initialize chunk reader: %w", err)
|
return nil, -1, fmt.Errorf("initialize chunk reader: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return chunkReader, nil
|
return chunkReader, decoded, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func formEncryptionParams(r *http.Request) (enc encryption.Params, err error) {
|
func formEncryptionParams(r *http.Request) (enc encryption.Params, err error) {
|
||||||
|
|
Loading…
Reference in a new issue