1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 18:07:01 +00:00

correctly handle recorded compressed response

see https://github.com/kataras/iris/issues/1569#issuecomment-664003098
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-07-26 20:28:31 +03:00
parent 613d3fc749
commit ad5e5d82ce
3 changed files with 24 additions and 8 deletions

View File

@@ -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