Browse Source

avoid .gz auto decompression

pull/809/head
Chris Lu 6 years ago
parent
commit
852ee21835
  1. 8
      weed/command/filer_copy.go
  2. 6
      weed/operation/submit.go
  3. 12
      weed/storage/needle_parse_multipart.go

8
weed/command/filer_copy.go

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

6
weed/operation/submit.go

@ -18,7 +18,6 @@ type FilePart struct {
Reader io.Reader
FileName string
FileSize int64
IsGzipped bool
MimeType string
ModTime int64 //in seconds
Replication string
@ -103,7 +102,6 @@ func newFilePart(fullPathFilename string) (ret FilePart, err error) {
ret.ModTime = fi.ModTime().UTC().Unix()
ret.FileSize = fi.Size()
ext := strings.ToLower(path.Ext(fullPathFilename))
ret.IsGzipped = ext == ".gz"
ret.FileName = fi.Name()
if 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)
}
} 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 {
return 0, e
}
@ -203,7 +201,7 @@ func (fi FilePart) Upload(maxMB int, master string, secret security.Secret) (ret
}
func upload_one_chunk(filename string, reader io.Reader, master,
fileUrl string, jwt security.EncodedJwt,
fileUrl string, jwt security.EncodedJwt,
) (size uint32, e error) {
glog.V(4).Info("Uploading part ", filename, " to ", fileUrl, "...")
uploadResult, uploadError := Upload(fileUrl, filename, reader, false,

12
weed/storage/needle_parse_multipart.go

@ -83,6 +83,9 @@ func parseMultipart(r *http.Request) (
}
if part.Header.Get("Content-Encoding") == "gzip" {
if unzipped, e := operation.UnGzipData(data); e == nil {
originalDataSize = len(unzipped)
}
isGzipped = true
} else if operation.IsGzippable(ext, mtype) {
if data, e = operation.GzipData(data); e != nil {
@ -90,15 +93,6 @@ func parseMultipart(r *http.Request) (
}
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

Loading…
Cancel
Save