1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-04 21:00:55 +00:00

gzip method support

This commit is contained in:
JessonChan 2016-03-17 19:40:29 +08:00
parent 5a9bff2000
commit 35e34261ab

View File

@ -30,13 +30,13 @@ import (
) )
var ( var (
//Content will only be compressed if content length is either unknown or greater than minGzipSize. //Content will only be compressed if content length is either unknown or greater than minGzipSize.
gzipMinLength int gzipMinLength int
//Default size==20B like nginx //Default size==20B like nginx
defaultGzipMinLength=20 defaultGzipMinLength = 20
//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.
includedMethods map[string]bool includedMethods map[string]bool
getMethodOnly bool getMethodOnly bool
) )
@ -96,9 +96,11 @@ func (ac acceptEncoder) put(wr resetWriter, level int) {
return return
} }
wr.Reset(nil) wr.Reset(nil)
//notice //notice
//compressionLevel==BestCompression DOES NOT MATTER //compressionLevel==BestCompression DOES NOT MATTER
//sync.Pool will not memory leak //sync.Pool will not memory leak
switch level { switch level {
case gzipCompressLevel: case gzipCompressLevel:
ac.customCompressLevelPool.Put(wr) ac.customCompressLevelPool.Put(wr)
@ -116,10 +118,10 @@ var (
bestCompressionPool: &sync.Pool{New: func() interface{} { wr, _ := gzip.NewWriterLevel(nil, flate.BestCompression); return wr }}, bestCompressionPool: &sync.Pool{New: func() interface{} { wr, _ := gzip.NewWriterLevel(nil, flate.BestCompression); return wr }},
} }
//according to the sec :http://tools.ietf.org/html/rfc2616#section-3.5 ,the deflate compress in http is zlib indeed //according to the sec :http://tools.ietf.org/html/rfc2616#section-3.5 ,the deflate compress in http is zlib indeed
//deflate //deflate
//The "zlib" format defined in RFC 1950 [31] in combination with //The "zlib" format defined in RFC 1950 [31] in combination with
//the "deflate" compression mechanism described in RFC 1951 [29]. //the "deflate" compression mechanism described in RFC 1951 [29].
deflateCompressEncoder = acceptEncoder{ deflateCompressEncoder = acceptEncoder{
name: "deflate", name: "deflate",
levelEncode: func(level int) resetWriter { wr, _ := zlib.NewWriterLevel(nil, level); return wr }, levelEncode: func(level int) resetWriter { wr, _ := zlib.NewWriterLevel(nil, level); return wr },