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
4db78f24
Commit
4db78f24
authored
Mar 22, 2016
by
JessonChan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change the function args of init gzip method
parent
959b9a5a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
9 deletions
+12
-9
acceptencoder.go
context/acceptencoder.go
+7
-8
hooks.go
hooks.go
+5
-1
No files found.
context/acceptencoder.go
View file @
4db78f24
...
...
@@ -25,15 +25,13 @@ import (
"strconv"
"strings"
"sync"
"github.com/astaxie/beego/config"
)
var
(
//Content will only be compressed if content length is either unknown or greater than gzipMinLength.
gzipMinLength
int
//Default size==20B same as nginx
defaultGzipMinLength
=
20
//Content will only be compressed if content length is either unknown or greater than gzipMinLength.
gzipMinLength
=
defaultGzipMinLength
//The compression level used for deflate compression. (0-9).
gzipCompressLevel
int
//List of HTTP methods to compress. If not set, only GET requests are compressed.
...
...
@@ -41,13 +39,14 @@ var (
getMethodOnly
bool
)
func
InitGzip
(
cf
config
.
Configer
)
{
gzipMinLength
=
cf
.
DefaultInt
(
"gzipMinLength"
,
defaultGzipMinLength
)
gzipCompressLevel
=
cf
.
DefaultInt
(
"gzipCompressLevel"
,
flate
.
BestSpeed
)
func
InitGzip
(
minLength
,
compressLevel
int
,
methods
[]
string
)
{
if
minLength
>=
0
{
gzipMinLength
=
minLength
}
gzipCompressLevel
=
compressLevel
if
gzipCompressLevel
<
flate
.
DefaultCompression
||
gzipCompressLevel
>
flate
.
BestCompression
{
gzipCompressLevel
=
flate
.
BestSpeed
}
methods
:=
cf
.
DefaultStrings
(
"includedMethods"
,
[]
string
{
"GET"
})
getMethodOnly
=
(
len
(
methods
)
==
0
)
||
(
len
(
methods
)
==
1
&&
strings
.
ToUpper
(
methods
[
0
])
==
"GET"
)
includedMethods
=
make
(
map
[
string
]
bool
,
len
(
methods
))
for
_
,
v
:=
range
methods
{
...
...
hooks.go
View file @
4db78f24
...
...
@@ -95,7 +95,11 @@ func registerAdmin() error {
func
registerGzip
()
error
{
if
BConfig
.
EnableGzip
{
context
.
InitGzip
(
AppConfig
)
context
.
InitGzip
(
AppConfig
.
DefaultInt
(
"gzipMinLength"
,
-
1
),
AppConfig
.
DefaultInt
(
"gzipCompressLevel"
,
-
1
),
AppConfig
.
DefaultStrings
(
"includedMethods"
,
[]
string
{
"GET"
}),
)
}
return
nil
}
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