1
0
mirror of https://github.com/kataras/iris.git synced 2026-02-08 19:55:55 +00:00

fix: ctx.Record and then iris.Compression flow

This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-07-30 20:13:59 +03:00
parent 53c6f46941
commit eacbcea653
5 changed files with 119 additions and 18 deletions

View File

@@ -243,12 +243,24 @@ func releaseCompressResponseWriter(w *CompressResponseWriter) {
func (w *CompressResponseWriter) FlushResponse() {
w.FlushHeaders()
/* this should NEVER happen, see `context.CompressWriter` method.
if rec, ok := w.ResponseWriter.(*ResponseRecorder); ok {
// Usecase: record, then compression.
w.CompressWriter.Close() // flushes and closes.
rec.FlushResponse()
return
}
*/
// write the status, after header set and before any flushed content sent.
w.ResponseWriter.FlushResponse()
w.CompressWriter.Close() // flushes and closes.
}
// FlushHeaders deletes the encoding headers if
// the compressed writer was disabled otherwise
// removes the content-length so next callers can re-calculate the correct length.
func (w *CompressResponseWriter) FlushHeaders() {
if w.Disabled {
w.Header().Del(VaryHeaderKey)
@@ -294,3 +306,18 @@ func (w *CompressResponseWriter) Flush() {
w.ResponseWriter.Flush()
}
// WriteTo writes the "p" to "dest" Writer using the compression that this compress writer was made of.
func (w *CompressResponseWriter) WriteTo(dest io.Writer, p []byte) (int, error) {
if w.Disabled {
return dest.Write(p)
}
cw, err := NewCompressWriter(dest, w.Encoding, w.Level)
if err != nil {
return 0, err
}
n, err := cw.Write(p)
cw.Close()
return n, err
}