Keep status when stream mode and compress
This commit is contained in:
parent
58a438167b
commit
9bd0fff319
6 changed files with 40 additions and 6 deletions
8
vendor/github.com/NYTimes/gziphandler/gzip.go
generated
vendored
8
vendor/github.com/NYTimes/gziphandler/gzip.go
generated
vendored
|
@ -82,6 +82,7 @@ type GzipResponseWriter struct {
|
|||
buf []byte // Holds the first part of the write before reaching the minSize or the end of the write.
|
||||
|
||||
contentTypes []string // Only compress if the response is one of these content-types. All are accepted if empty.
|
||||
flushed bool // Indicate if the stream was already flushed
|
||||
}
|
||||
|
||||
// Write appends data to the gzip writer.
|
||||
|
@ -167,7 +168,8 @@ func (w *GzipResponseWriter) init() {
|
|||
func (w *GzipResponseWriter) Close() error {
|
||||
if w.gw == nil {
|
||||
// Gzip not trigged yet, write out regular response.
|
||||
if w.code != 0 {
|
||||
// WriteHeader only if it wasn't already wrote by a Flush
|
||||
if !w.flushed && w.code != 0 {
|
||||
w.ResponseWriter.WriteHeader(w.code)
|
||||
}
|
||||
if w.buf != nil {
|
||||
|
@ -195,7 +197,11 @@ func (w *GzipResponseWriter) Flush() {
|
|||
}
|
||||
|
||||
if fw, ok := w.ResponseWriter.(http.Flusher); ok {
|
||||
if !w.flushed && w.code != 0 {
|
||||
w.ResponseWriter.WriteHeader(w.code)
|
||||
}
|
||||
fw.Flush()
|
||||
w.flushed = true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue