Browse Source

adjusting gzip logic

pull/2/head
Chris Lu 12 years ago
parent
commit
9630825576
  1. 2
      weed-fs/src/cmd/weed/volume.go
  2. 6
      weed-fs/src/pkg/storage/compress.go
  3. 2
      weed-fs/src/pkg/storage/needle.go

2
weed-fs/src/cmd/weed/volume.go

@ -105,7 +105,7 @@ func GetHandler(w http.ResponseWriter, r *http.Request) {
if ext != "" { if ext != "" {
mtype := mime.TypeByExtension(ext) mtype := mime.TypeByExtension(ext)
w.Header().Set("Content-Type", mtype) w.Header().Set("Content-Type", mtype)
if storage.IsCompressable(ext, mtype) {
if storage.IsGzippable(ext, mtype) {
if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") { if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
w.Header().Set("Content-Encoding", "gzip") w.Header().Set("Content-Encoding", "gzip")
} else { } else {

6
weed-fs/src/pkg/storage/compress.go

@ -8,12 +8,12 @@ import (
"strings" "strings"
) )
func IsCompressable(ext, mtype string) bool {
func IsGzippable(ext, mtype string) bool {
if ext == ".zip" { if ext == ".zip" {
return true
return false
} }
if ext == ".rar" { if ext == ".rar" {
return true
return false
} }
if strings.Index(mtype,"text/")==0 { if strings.Index(mtype,"text/")==0 {
return true return true

2
weed-fs/src/pkg/storage/needle.go

@ -40,7 +40,7 @@ func NewNeedle(r *http.Request) (n *Needle, fname string, e error) {
if dotIndex > 0 { if dotIndex > 0 {
ext := fname[dotIndex:] ext := fname[dotIndex:]
mtype := mime.TypeByExtension(ext) mtype := mime.TypeByExtension(ext)
if IsCompressable(ext, mtype) {
if IsGzippable(ext, mtype) {
data = GzipData(data) data = GzipData(data)
} }
} }

Loading…
Cancel
Save