From 4b858b562a0887e10bfd0414dc87e68f1af31c3a Mon Sep 17 00:00:00 2001 From: kannappanr <30541348+kannappanr@users.noreply.github.com> Date: Thu, 2 May 2019 08:28:18 -0700 Subject: [PATCH] Compression: Handle auto encryption when size is unknown (#7600) When size is unknown and auto encryption is enabled, and compression is set to true, putobject API is failing. Moving adding the SSE-S3 header as part of the request to before checking if compression can be done, otherwise the size is set to -1 and that seems to cause problems. --- cmd/object-handlers.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/object-handlers.go b/cmd/object-handlers.go index f2fa48ef9..3b5585211 100644 --- a/cmd/object-handlers.go +++ b/cmd/object-handlers.go @@ -1176,6 +1176,11 @@ func (api objectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Req } } + // This request header needs to be set prior to setting ObjectOptions + if globalAutoEncryption && !crypto.SSEC.IsRequested(r.Header) { + r.Header.Add(crypto.SSEHeader, crypto.SSEAlgorithmAES256) + } + actualSize := size if objectAPI.IsCompressionSupported() && isCompressible(r.Header, object) && size > 0 { @@ -1205,10 +1210,6 @@ func (api objectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Req rawReader := hashReader pReader := NewPutObjReader(rawReader, nil, nil) - // This request header needs to be set prior to setting ObjectOptions - if globalAutoEncryption && !crypto.SSEC.IsRequested(r.Header) { - r.Header.Add(crypto.SSEHeader, crypto.SSEAlgorithmAES256) - } // get gateway encryption options var opts ObjectOptions opts, err = putOpts(ctx, r, bucket, object, metadata)