1
0
mirror of https://github.com/astaxie/beego.git synced 2024-12-25 13:00:51 +00:00

remove not support encoding

This commit is contained in:
Maxgis 2016-07-27 09:31:53 +08:00
parent e951c555e4
commit 5485e1334f
2 changed files with 23 additions and 7 deletions

View File

@ -209,9 +209,13 @@ func parseEncoding(r *http.Request) string {
continue
}
vs := strings.Split(v, ";")
var cf acceptEncoder
var ok bool
if cf, ok = encoderMap[vs[0]]; !ok {
continue
}
if len(vs) == 1 {
lastQ = q{vs[0], 1}
break
return cf.name
}
if len(vs) == 2 {
f, _ := strconv.ParseFloat(strings.Replace(vs[1], "q=", "", -1), 64)
@ -219,12 +223,9 @@ func parseEncoding(r *http.Request) string {
continue
}
if f > lastQ.value {
lastQ = q{vs[0], f}
lastQ = q{cf.name, f}
}
}
}
if cf, ok := encoderMap[lastQ.name]; ok {
return cf.name
}
return ""
return lastQ.name
}

View File

@ -41,4 +41,19 @@ func Test_ExtractEncoding(t *testing.T) {
if parseEncoding(&http.Request{Header: map[string][]string{"Accept-Encoding": {"*"}}}) != "gzip" {
t.Fail()
}
if parseEncoding(&http.Request{Header: map[string][]string{"Accept-Encoding": {"x,gzip,deflate"}}}) != "gzip" {
t.Fail()
}
if parseEncoding(&http.Request{Header: map[string][]string{"Accept-Encoding": {"gzip,x,deflate"}}}) != "gzip" {
t.Fail()
}
if parseEncoding(&http.Request{Header: map[string][]string{"Accept-Encoding": {"gzip;q=0.5,x,deflate"}}}) != "deflate" {
t.Fail()
}
if parseEncoding(&http.Request{Header: map[string][]string{"Accept-Encoding": {"x"}}}) != "" {
t.Fail()
}
if parseEncoding(&http.Request{Header: map[string][]string{"Accept-Encoding": {"gzip;q=0.5,x;q=0.8"}}}) != "gzip" {
t.Fail()
}
}