Browse Source

detect more gzippable content

pull/809/head
Chris Lu 6 years ago
parent
commit
c043fd17cb
  1. 27
      weed/operation/compress.go
  2. 2
      weed/storage/needle_parse_multipart.go

27
weed/operation/compress.go

@ -8,21 +8,41 @@ import (
"strings" "strings"
"github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/glog"
"golang.org/x/tools/godoc/util"
) )
/* /*
* Default more not to gzip since gzip can be done on client side. * Default more not to gzip since gzip can be done on client side.
*/ */
func IsGzippable(ext, mtype string) bool {
func IsGzippable(ext, mtype string, data []byte) bool {
// text
if strings.HasPrefix(mtype, "text/") { if strings.HasPrefix(mtype, "text/") {
return true return true
} }
// images
switch ext {
case ".svg", ".bmp":
return true
}
if strings.HasPrefix(mtype, "image/") {
return false
}
// by file name extention
switch ext { switch ext {
case ".zip", ".rar", ".gz", ".bz2", ".xz": case ".zip", ".rar", ".gz", ".bz2", ".xz":
return false return false
case ".pdf", ".txt", ".html", ".htm", ".css", ".js", ".json": case ".pdf", ".txt", ".html", ".htm", ".css", ".js", ".json":
return true return true
case ".php", ".java", ".go", ".rb", ".c", ".cpp", ".h", ".hpp":
return true
case ".png", ".jpg", ".jpeg", "":
return true
} }
// by mime type
if strings.HasPrefix(mtype, "application/") { if strings.HasPrefix(mtype, "application/") {
if strings.HasSuffix(mtype, "xml") { if strings.HasSuffix(mtype, "xml") {
return true return true
@ -31,7 +51,10 @@ func IsGzippable(ext, mtype string) bool {
return true return true
} }
} }
return false
isMostlyText := util.IsText(data)
return isMostlyText
} }
func GzipData(input []byte) ([]byte, error) { func GzipData(input []byte) ([]byte, error) {

2
weed/storage/needle_parse_multipart.go

@ -87,7 +87,7 @@ func parseMultipart(r *http.Request) (
originalDataSize = len(unzipped) originalDataSize = len(unzipped)
} }
isGzipped = true isGzipped = true
} else if operation.IsGzippable(ext, mtype) {
} else if operation.IsGzippable(ext, mtype, data) {
if data, e = operation.GzipData(data); e != nil { if data, e = operation.GzipData(data); e != nil {
return return
} }

Loading…
Cancel
Save