1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 12:20:54 +00:00

change the function args of init gzip method

This commit is contained in:
JessonChan 2016-03-22 16:42:42 +08:00
parent 959b9a5a58
commit 4db78f243e
2 changed files with 12 additions and 9 deletions

View File

@ -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 {

View File

@ -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
}