adding uncompressing support!
git-svn-id: https://weed-fs.googlecode.com/svn/trunk@61 282b0af5-e82d-9cf1-ede4-77906d7719d0
This commit is contained in:
@@ -65,7 +65,11 @@ func GetHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
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.IsCompressable(ext, mtype){
|
||||||
w.Header().Set("Content-Encoding", "gzip")
|
if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip"){
|
||||||
|
w.Header().Set("Content-Encoding", "gzip")
|
||||||
|
}else{
|
||||||
|
n.Data = storage.UnGzipData(n.Data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
w.Write(n.Data)
|
w.Write(n.Data)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"compress/flate"
|
"compress/flate"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -34,3 +35,13 @@ func GzipData(input []byte) []byte {
|
|||||||
}
|
}
|
||||||
return buf.Bytes()
|
return buf.Bytes()
|
||||||
}
|
}
|
||||||
|
func UnGzipData(input []byte) []byte {
|
||||||
|
buf := bytes.NewBuffer(input)
|
||||||
|
r, _ := gzip.NewReader(buf)
|
||||||
|
defer r.Close()
|
||||||
|
output, err := ioutil.ReadAll(r)
|
||||||
|
if err!=nil {
|
||||||
|
log.Printf("error uncompressing data:%s\n", err)
|
||||||
|
}
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user