mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
correctly handle recorded compressed response
see https://github.com/kataras/iris/issues/1569#issuecomment-664003098
This commit is contained in:
parent
613d3fc749
commit
ad5e5d82ce
|
@ -1,4 +1,5 @@
|
|||
// package main contains an example on how to use the ReadForm, but with the same way you can do the ReadJSON & ReadJSON
|
||||
// package main contains an example on how to use the ReadQuery,
|
||||
// same way you can do the ReadJSON & ReadProtobuf and e.t.c.
|
||||
package main
|
||||
|
||||
import (
|
||||
|
|
|
@ -241,17 +241,22 @@ func releaseCompressResponseWriter(w *CompressResponseWriter) {
|
|||
// and writes the status code.
|
||||
// Called automatically before `EndResponse`.
|
||||
func (w *CompressResponseWriter) FlushResponse() {
|
||||
w.FlushHeaders()
|
||||
|
||||
// write the status, after header set and before any flushed content sent.
|
||||
w.ResponseWriter.FlushResponse()
|
||||
|
||||
w.CompressWriter.Close() // flushes and closes.
|
||||
}
|
||||
|
||||
func (w *CompressResponseWriter) FlushHeaders() {
|
||||
if w.Disabled {
|
||||
w.Header().Del(VaryHeaderKey)
|
||||
w.Header().Del(ContentEncodingHeaderKey)
|
||||
w.CompressWriter.Reset(&noOpWriter{})
|
||||
w.CompressWriter.Close()
|
||||
} else {
|
||||
w.ResponseWriter.Header().Del(ContentLengthHeaderKey)
|
||||
w.CompressWriter.Close() // flushes and closes.
|
||||
}
|
||||
|
||||
w.ResponseWriter.FlushResponse()
|
||||
}
|
||||
|
||||
// EndResponse reeases the writers.
|
||||
|
|
|
@ -152,14 +152,24 @@ func (w *ResponseRecorder) FlushResponse() {
|
|||
}
|
||||
}
|
||||
|
||||
// NOTE: before the ResponseWriter.Write in order to:
|
||||
// set the given status code even if the body is empty.
|
||||
w.ResponseWriter.FlushResponse()
|
||||
cw, mustWriteToClose := w.ResponseWriter.(*CompressResponseWriter)
|
||||
if mustWriteToClose { // see #1569#issuecomment-664003098
|
||||
cw.FlushHeaders()
|
||||
} else {
|
||||
// NOTE: before the ResponseWriter.Write in order to:
|
||||
// set the given status code even if the body is empty.
|
||||
w.ResponseWriter.FlushResponse()
|
||||
}
|
||||
|
||||
if len(w.chunks) > 0 {
|
||||
// ignore error
|
||||
w.ResponseWriter.Write(w.chunks)
|
||||
}
|
||||
|
||||
if mustWriteToClose {
|
||||
cw.CompressWriter.Close()
|
||||
cw.ResponseWriter.FlushResponse()
|
||||
}
|
||||
}
|
||||
|
||||
// Clone returns a clone of this response writer
|
||||
|
|
Loading…
Reference in New Issue
Block a user