From e63d24637dfd56eabd9067a2bcf824de66f92d07 Mon Sep 17 00:00:00 2001 From: JessonChan Date: Tue, 15 Dec 2015 14:08:58 +0800 Subject: [PATCH 1/2] go test fixed --- staticfile_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/staticfile_test.go b/staticfile_test.go index e635fcc6..097ee07e 100644 --- a/staticfile_test.go +++ b/staticfile_test.go @@ -4,6 +4,7 @@ import ( "bytes" "compress/flate" "compress/gzip" + "compress/zlib" "io" "io/ioutil" "os" @@ -43,7 +44,7 @@ func TestOpenStaticFileGzip_1(t *testing.T) { func TestOpenStaticFileDeflate_1(t *testing.T) { file, _ := os.Open(licenseFile) var zipBuf bytes.Buffer - fileWriter, _ := flate.NewWriter(&zipBuf, flate.BestCompression) + fileWriter, _ := zlib.NewWriterLevel(&zipBuf, flate.BestCompression) io.Copy(fileWriter, file) fileWriter.Close() content, _ := ioutil.ReadAll(&zipBuf) From ccc008c257908afe4463160a8014e62dab37e3fe Mon Sep 17 00:00:00 2001 From: JessonChan Date: Tue, 15 Dec 2015 14:29:07 +0800 Subject: [PATCH 2/2] compress fixed --- context/acceptencoder.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/context/acceptencoder.go b/context/acceptencoder.go index 1bd2cc3d..0a0586ac 100644 --- a/context/acceptencoder.go +++ b/context/acceptencoder.go @@ -18,6 +18,7 @@ import ( "bytes" "compress/flate" "compress/gzip" + "compress/zlib" "io" "net/http" "os" @@ -31,9 +32,13 @@ type acceptEncoder struct { } var ( - noneCompressEncoder = acceptEncoder{"", func(wr io.Writer, level int) (io.Writer, error) { return wr, nil }} - gzipCompressEncoder = acceptEncoder{"gzip", func(wr io.Writer, level int) (io.Writer, error) { return gzip.NewWriterLevel(wr, level) }} - deflateCompressEncoder = acceptEncoder{"deflate", func(wr io.Writer, level int) (io.Writer, error) { return flate.NewWriter(wr, level) }} + noneCompressEncoder = acceptEncoder{"", func(wr io.Writer, level int) (io.Writer, error) { return wr, nil }} + gzipCompressEncoder = acceptEncoder{"gzip", func(wr io.Writer, level int) (io.Writer, error) { return gzip.NewWriterLevel(wr, level) }} + //according to the sec :http://tools.ietf.org/html/rfc2616#section-3.5 ,the deflate compress in http is zlib indeed + //deflate + //The "zlib" format defined in RFC 1950 [31] in combination with + //the "deflate" compression mechanism described in RFC 1951 [29]. + deflateCompressEncoder = acceptEncoder{"deflate", func(wr io.Writer, level int) (io.Writer, error) { return zlib.NewWriterLevel(wr, level) }} ) var (