mirror of
https://github.com/astaxie/beego.git
synced 2024-11-29 10:11:28 +00:00
Merge pull request #2065 from Maxgis/issue_accept_encoding
remove not support encoding
This commit is contained in:
commit
909afa9352
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user