Remove GZIPHandler fork.
This commit is contained in:
parent
2296aab5a8
commit
7c35337999
7 changed files with 214 additions and 101 deletions
23
vendor/github.com/NYTimes/gziphandler/gzip.go
generated
vendored
23
vendor/github.com/NYTimes/gziphandler/gzip.go
generated
vendored
|
@ -3,7 +3,6 @@ package gziphandler
|
|||
import (
|
||||
"bufio"
|
||||
"compress/gzip"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
|
@ -106,7 +105,7 @@ func (w *GzipResponseWriter) Write(b []byte) (int, error) {
|
|||
// If the global writes are bigger than the minSize and we're about to write
|
||||
// a response containing a content type we want to handle, enable
|
||||
// compression.
|
||||
if len(w.buf) >= w.minSize && handleContentType(w.contentTypes, w) {
|
||||
if len(w.buf) >= w.minSize && handleContentType(w.contentTypes, w) && w.Header().Get(contentEncoding) == "" {
|
||||
err := w.startGzip()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
@ -135,7 +134,7 @@ func (w *GzipResponseWriter) startGzip() error {
|
|||
// Initialize the GZIP response.
|
||||
w.init()
|
||||
|
||||
// Flush the buffer into the gzip reponse.
|
||||
// Flush the buffer into the gzip response.
|
||||
n, err := w.gw.Write(w.buf)
|
||||
|
||||
// This should never happen (per io.Writer docs), but if the write didn't
|
||||
|
@ -235,14 +234,10 @@ func NewGzipLevelHandler(level int) (func(http.Handler) http.Handler, error) {
|
|||
// NewGzipLevelAndMinSize behave as NewGzipLevelHandler except it let the caller
|
||||
// specify the minimum size before compression.
|
||||
func NewGzipLevelAndMinSize(level, minSize int) (func(http.Handler) http.Handler, error) {
|
||||
return GzipHandlerWithOpts(&GzipResponseWriter{}, CompressionLevel(level), MinSize(minSize))
|
||||
return GzipHandlerWithOpts(CompressionLevel(level), MinSize(minSize))
|
||||
}
|
||||
|
||||
func GzipHandlerWithOpts(gw GzipWriter, opts ...option) (func(http.Handler) http.Handler, error) {
|
||||
if gw == nil {
|
||||
return nil, errors.New("the GzipWriter must be defined")
|
||||
}
|
||||
|
||||
func GzipHandlerWithOpts(opts ...option) (func(http.Handler) http.Handler, error) {
|
||||
c := &config{
|
||||
level: gzip.DefaultCompression,
|
||||
minSize: DefaultMinSize,
|
||||
|
@ -263,10 +258,12 @@ func GzipHandlerWithOpts(gw GzipWriter, opts ...option) (func(http.Handler) http
|
|||
w.Header().Add(vary, acceptEncoding)
|
||||
|
||||
if acceptsGzip(r) {
|
||||
gw.SetResponseWriter(w)
|
||||
gw.setIndex(index)
|
||||
gw.setMinSize(c.minSize)
|
||||
gw.setContentTypes(c.contentTypes)
|
||||
gw := &GzipResponseWriter{
|
||||
ResponseWriter: w,
|
||||
index: index,
|
||||
minSize: c.minSize,
|
||||
contentTypes: c.contentTypes,
|
||||
}
|
||||
defer gw.Close()
|
||||
|
||||
h.ServeHTTP(gw, r)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue