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
891be34f
Commit
891be34f
authored
Nov 10, 2015
by
JessonChan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
encoding should be specify
parent
0bc70e88
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
9 deletions
+12
-9
acceptencoder.go
acceptencoder/acceptencoder.go
+12
-9
No files found.
acceptencoder/acceptencoder.go
View file @
891be34f
...
...
@@ -23,7 +23,7 @@ import (
"strconv"
"strings"
"
gopkg.in/bufio.v1
"
"
bytes
"
)
// 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,
// WriteBody reads writes content to writer by the specific encoding(gzip/deflate)
func
WriteBody
(
encoding
string
,
writer
io
.
Writer
,
content
[]
byte
)
(
bool
,
string
,
error
)
{
return
writeLevel
(
encoding
,
writer
,
b
ufio
.
NewBuffer
(
content
),
flate
.
BestSpeed
)
return
writeLevel
(
encoding
,
writer
,
b
ytes
.
NewBuffer
(
content
),
flate
.
BestSpeed
)
}
// writeLevel reads from reader,writes to writer by specific encoding and compress level
...
...
@@ -84,6 +84,15 @@ type q struct {
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
{
acceptEncoding
:=
r
.
Header
.
Get
(
"Accept-Encoding"
)
if
acceptEncoding
==
""
{
...
...
@@ -110,11 +119,5 @@ func parseEncoding(r *http.Request) string {
}
}
}
if
lastQ
.
name
==
"*"
{
return
"gzip"
}
if
lastQ
.
name
==
"identity"
{
return
""
}
return
lastQ
.
name
return
encodingMap
[
lastQ
.
name
]
}
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