Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
909afa93
Commit
909afa93
authored
Jul 27, 2016
by
astaxie
Committed by
GitHub
Jul 27, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2065 from Maxgis/issue_accept_encoding
remove not support encoding
parents
d08e3d1b
5485e133
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
7 deletions
+23
-7
acceptencoder.go
context/acceptencoder.go
+8
-7
acceptencoder_test.go
context/acceptencoder_test.go
+15
-0
No files found.
context/acceptencoder.go
View file @
909afa93
...
...
@@ -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
}
context/acceptencoder_test.go
View file @
909afa93
...
...
@@ -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
()
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment