Commit 891be34f authored by JessonChan's avatar JessonChan

encoding should be specify

parent 0bc70e88
...@@ -23,7 +23,7 @@ import ( ...@@ -23,7 +23,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"gopkg.in/bufio.v1" "bytes"
) )
// WriteFile reads from file and writes to writer by the specific encoding(gzip/deflate) // WriteFile reads from file and writes to writer by the specific encoding(gzip/deflate)
...@@ -35,7 +35,7 @@ func WriteFile(encoding string, writer io.Writer, file *os.File) (bool, string, ...@@ -35,7 +35,7 @@ func WriteFile(encoding string, writer io.Writer, file *os.File) (bool, string,
// WriteBody reads writes content to writer by the specific encoding(gzip/deflate) // WriteBody reads writes content to writer by the specific encoding(gzip/deflate)
func WriteBody(encoding string, writer io.Writer, content []byte) (bool, string, error) { func WriteBody(encoding string, writer io.Writer, content []byte) (bool, string, error) {
return writeLevel(encoding, writer, bufio.NewBuffer(content), flate.BestSpeed) return writeLevel(encoding, writer, bytes.NewBuffer(content), flate.BestSpeed)
} }
// writeLevel reads from reader,writes to writer by specific encoding and compress level // writeLevel reads from reader,writes to writer by specific encoding and compress level
...@@ -84,6 +84,15 @@ type q struct { ...@@ -84,6 +84,15 @@ type q struct {
value float64 value float64
} }
var (
encodingMap = map[string]string{ // all the other compress methods will ignore
"gzip": "gzip",
"deflate": "deflate",
"*": "gzip", // * means any compress will accept,we prefer gzip
"identity": "", // identity means none-compress
}
)
func parseEncoding(r *http.Request) string { func parseEncoding(r *http.Request) string {
acceptEncoding := r.Header.Get("Accept-Encoding") acceptEncoding := r.Header.Get("Accept-Encoding")
if acceptEncoding == "" { if acceptEncoding == "" {
...@@ -110,11 +119,5 @@ func parseEncoding(r *http.Request) string { ...@@ -110,11 +119,5 @@ func parseEncoding(r *http.Request) string {
} }
} }
} }
if lastQ.name == "*" { return encodingMap[lastQ.name]
return "gzip"
}
if lastQ.name == "identity" {
return ""
}
return lastQ.name
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment