avoid .gz auto decompression

This commit is contained in:
Chris Lu 2018-12-22 13:58:16 -08:00
parent be946c9e54
commit 852ee21835
3 changed files with 6 additions and 20 deletions

View file

@ -15,7 +15,6 @@ import (
"github.com/chrislusf/seaweedfs/weed/util" "github.com/chrislusf/seaweedfs/weed/util"
"io" "io"
"net/http" "net/http"
"path"
"strconv" "strconv"
"time" "time"
) )
@ -165,7 +164,6 @@ func uploadFileAsOne(filerAddress, filerGrpcAddress string, urlFolder string, f
// upload the file content // upload the file content
fileName := filepath.Base(f.Name()) fileName := filepath.Base(f.Name())
mimeType := detectMimeType(f) mimeType := detectMimeType(f)
isGzipped := isGzipped(fileName)
var chunks []*filer_pb.FileChunk var chunks []*filer_pb.FileChunk
@ -184,7 +182,7 @@ func uploadFileAsOne(filerAddress, filerGrpcAddress string, urlFolder string, f
targetUrl := "http://" + assignResult.Url + "/" + assignResult.Fid targetUrl := "http://" + assignResult.Url + "/" + assignResult.Fid
uploadResult, err := operation.Upload(targetUrl, fileName, f, isGzipped, mimeType, nil, "") uploadResult, err := operation.Upload(targetUrl, fileName, f, false, mimeType, nil, "")
if err != nil { if err != nil {
fmt.Printf("upload data %v to %s: %v\n", fileName, targetUrl, err) fmt.Printf("upload data %v to %s: %v\n", fileName, targetUrl, err)
return false return false
@ -318,10 +316,6 @@ func uploadFileInChunks(filerAddress, filerGrpcAddress string, urlFolder string,
return true return true
} }
func isGzipped(filename string) bool {
return strings.ToLower(path.Ext(filename)) == ".gz"
}
func detectMimeType(f *os.File) string { func detectMimeType(f *os.File) string {
head := make([]byte, 512) head := make([]byte, 512)
f.Seek(0, 0) f.Seek(0, 0)

View file

@ -18,7 +18,6 @@ type FilePart struct {
Reader io.Reader Reader io.Reader
FileName string FileName string
FileSize int64 FileSize int64
IsGzipped bool
MimeType string MimeType string
ModTime int64 //in seconds ModTime int64 //in seconds
Replication string Replication string
@ -103,7 +102,6 @@ func newFilePart(fullPathFilename string) (ret FilePart, err error) {
ret.ModTime = fi.ModTime().UTC().Unix() ret.ModTime = fi.ModTime().UTC().Unix()
ret.FileSize = fi.Size() ret.FileSize = fi.Size()
ext := strings.ToLower(path.Ext(fullPathFilename)) ext := strings.ToLower(path.Ext(fullPathFilename))
ret.IsGzipped = ext == ".gz"
ret.FileName = fi.Name() ret.FileName = fi.Name()
if ext != "" { if ext != "" {
ret.MimeType = mime.TypeByExtension(ext) ret.MimeType = mime.TypeByExtension(ext)
@ -193,7 +191,7 @@ func (fi FilePart) Upload(maxMB int, master string, secret security.Secret) (ret
cm.DeleteChunks(master) cm.DeleteChunks(master)
} }
} else { } else {
ret, e := Upload(fileUrl, baseName, fi.Reader, fi.IsGzipped, fi.MimeType, nil, jwt) ret, e := Upload(fileUrl, baseName, fi.Reader, false, fi.MimeType, nil, jwt)
if e != nil { if e != nil {
return 0, e return 0, e
} }

View file

@ -83,6 +83,9 @@ func parseMultipart(r *http.Request) (
} }
if part.Header.Get("Content-Encoding") == "gzip" { if part.Header.Get("Content-Encoding") == "gzip" {
if unzipped, e := operation.UnGzipData(data); e == nil {
originalDataSize = len(unzipped)
}
isGzipped = true isGzipped = true
} else if operation.IsGzippable(ext, mtype) { } else if operation.IsGzippable(ext, mtype) {
if data, e = operation.GzipData(data); e != nil { if data, e = operation.GzipData(data); e != nil {
@ -90,15 +93,6 @@ func parseMultipart(r *http.Request) (
} }
isGzipped = true isGzipped = true
} }
if ext == ".gz" {
if strings.HasSuffix(fileName, ".css.gz") ||
strings.HasSuffix(fileName, ".html.gz") ||
strings.HasSuffix(fileName, ".txt.gz") ||
strings.HasSuffix(fileName, ".js.gz") {
fileName = fileName[:len(fileName)-3]
isGzipped = true
}
}
} }
return return