0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00

Use ioutil.Discard instead for unneeded bytes.

This commit is contained in:
Abiola Ibrahim 2015-12-09 18:44:25 +01:00
parent 23631cfaca
commit a44d59f1e5
2 changed files with 5 additions and 8 deletions

View file

@ -3,10 +3,10 @@
package gzip
import (
"bytes"
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"
@ -49,12 +49,9 @@ outer:
r.Header.Del("Accept-Encoding")
// gzipWriter modifies underlying writer at init,
// use a buffer instead to leave ResponseWriter in
// use a discard writer instead to leave ResponseWriter in
// original form.
var buf = &bytes.Buffer{}
defer buf.Reset()
gzipWriter, err := newWriter(c, buf)
gzipWriter, err := newWriter(c, ioutil.Discard)
if err != nil {
// should not happen
return http.StatusInternalServerError, err
@ -65,7 +62,7 @@ outer:
var rw http.ResponseWriter
// if no response filter is used
if len(c.ResponseFilters) == 0 {
// replace buffer with ResponseWriter
// replace discard writer with ResponseWriter
gzipWriter.Reset(w)
rw = gz
} else {

View file

@ -52,7 +52,7 @@ func (r *ResponseFilterWriter) WriteHeader(code int) {
}
if r.shouldCompress {
// replace buffer with ResponseWriter
// replace discard writer with ResponseWriter
if gzWriter, ok := r.gzipResponseWriter.Writer.(*gzip.Writer); ok {
gzWriter.Reset(r.ResponseWriter)
}