compress: preserve status code
This commit is contained in:
parent
ec3e2c08b8
commit
5313922bb7
6 changed files with 189 additions and 56 deletions
8
vendor/github.com/NYTimes/gziphandler/wrapper.go
generated
vendored
8
vendor/github.com/NYTimes/gziphandler/wrapper.go
generated
vendored
|
@ -23,6 +23,7 @@ type GzipWriter interface {
|
|||
SetResponseWriter(http.ResponseWriter)
|
||||
setIndex(int)
|
||||
setMinSize(int)
|
||||
setContentTypes([]string)
|
||||
}
|
||||
|
||||
func (w *GzipResponseWriter) SetResponseWriter(rw http.ResponseWriter) {
|
||||
|
@ -37,6 +38,10 @@ func (w *GzipResponseWriter) setMinSize(minSize int) {
|
|||
w.minSize = minSize
|
||||
}
|
||||
|
||||
func (w *GzipResponseWriter) setContentTypes(contentTypes []string) {
|
||||
w.contentTypes = contentTypes
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
type GzipResponseWriterWrapper struct {
|
||||
|
@ -45,6 +50,9 @@ type GzipResponseWriterWrapper struct {
|
|||
|
||||
func (g *GzipResponseWriterWrapper) Write(b []byte) (int, error) {
|
||||
if g.gw == nil && isEncoded(g.Header()) {
|
||||
if g.code != 0 {
|
||||
g.ResponseWriter.WriteHeader(g.code)
|
||||
}
|
||||
return g.ResponseWriter.Write(b)
|
||||
}
|
||||
return g.GzipResponseWriter.Write(b)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue