From 7335e6219921fd3976179f6a74ea4a2dcdc43e1e Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sun, 1 Mar 2020 23:37:02 -0800 Subject: [PATCH] volume: PUT also conditionally gzip compress --- weed/storage/needle/needle.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/weed/storage/needle/needle.go b/weed/storage/needle/needle.go index 494cc138e..022e8bf14 100644 --- a/weed/storage/needle/needle.go +++ b/weed/storage/needle/needle.go @@ -12,6 +12,7 @@ import ( "github.com/chrislusf/seaweedfs/weed/images" . "github.com/chrislusf/seaweedfs/weed/storage/types" + "github.com/chrislusf/seaweedfs/weed/util" ) const ( @@ -63,7 +64,7 @@ func ParseUpload(r *http.Request, sizeLimit int64) ( if r.Method == "POST" { fileName, data, mimeType, isGzipped, originalDataSize, isChunkedFile, e = parseMultipart(r, sizeLimit) } else { - isGzipped = false + isGzipped = r.Header.Get("Content-Encoding") == "gzip" mimeType = r.Header.Get("Content-Type") fileName = "" data, e = ioutil.ReadAll(io.LimitReader(r.Body, sizeLimit+1)) @@ -72,6 +73,16 @@ func ParseUpload(r *http.Request, sizeLimit int64) ( io.Copy(ioutil.Discard, r.Body) } r.Body.Close() + if isGzipped { + if unzipped, e := util.UnGzipData(data); e == nil { + originalDataSize = len(unzipped) + } + } else if shouldGzip, _ := util.IsGzippableFileType("", mimeType); shouldGzip { + if compressedData, err := util.GzipData(data); err == nil { + data = compressedData + isGzipped = true + } + } } if e != nil { return