mirror of
https://github.com/astaxie/beego.git
synced 2024-11-26 02:51:28 +00:00
change the function args of init gzip method
This commit is contained in:
parent
959b9a5a58
commit
4db78f243e
@ -25,15 +25,13 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/astaxie/beego/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
//Content will only be compressed if content length is either unknown or greater than gzipMinLength.
|
|
||||||
gzipMinLength int
|
|
||||||
//Default size==20B same as nginx
|
//Default size==20B same as nginx
|
||||||
defaultGzipMinLength = 20
|
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).
|
//The compression level used for deflate compression. (0-9).
|
||||||
gzipCompressLevel int
|
gzipCompressLevel int
|
||||||
//List of HTTP methods to compress. If not set, only GET requests are compressed.
|
//List of HTTP methods to compress. If not set, only GET requests are compressed.
|
||||||
@ -41,13 +39,14 @@ var (
|
|||||||
getMethodOnly bool
|
getMethodOnly bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitGzip(cf config.Configer) {
|
func InitGzip(minLength, compressLevel int, methods []string) {
|
||||||
gzipMinLength = cf.DefaultInt("gzipMinLength", defaultGzipMinLength)
|
if minLength >= 0 {
|
||||||
gzipCompressLevel = cf.DefaultInt("gzipCompressLevel", flate.BestSpeed)
|
gzipMinLength = minLength
|
||||||
|
}
|
||||||
|
gzipCompressLevel = compressLevel
|
||||||
if gzipCompressLevel < flate.DefaultCompression || gzipCompressLevel > flate.BestCompression {
|
if gzipCompressLevel < flate.DefaultCompression || gzipCompressLevel > flate.BestCompression {
|
||||||
gzipCompressLevel = flate.BestSpeed
|
gzipCompressLevel = flate.BestSpeed
|
||||||
}
|
}
|
||||||
methods := cf.DefaultStrings("includedMethods", []string{"GET"})
|
|
||||||
getMethodOnly = (len(methods) == 0) || (len(methods) == 1 && strings.ToUpper(methods[0]) == "GET")
|
getMethodOnly = (len(methods) == 0) || (len(methods) == 1 && strings.ToUpper(methods[0]) == "GET")
|
||||||
includedMethods = make(map[string]bool, len(methods))
|
includedMethods = make(map[string]bool, len(methods))
|
||||||
for _, v := range methods {
|
for _, v := range methods {
|
||||||
|
6
hooks.go
6
hooks.go
@ -95,7 +95,11 @@ func registerAdmin() error {
|
|||||||
|
|
||||||
func registerGzip() error {
|
func registerGzip() error {
|
||||||
if BConfig.EnableGzip {
|
if BConfig.EnableGzip {
|
||||||
context.InitGzip(AppConfig)
|
context.InitGzip(
|
||||||
|
AppConfig.DefaultInt("gzipMinLength", -1),
|
||||||
|
AppConfig.DefaultInt("gzipCompressLevel", -1),
|
||||||
|
AppConfig.DefaultStrings("includedMethods", []string{"GET"}),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user