diff options
author | WeidiDeng <[email protected]> | 2024-07-28 07:46:56 +0800 |
---|---|---|
committer | Matthew Holt <[email protected]> | 2024-07-29 08:51:25 -0600 |
commit | 898ef9f212b768e12cd95af897e46d7896950aeb (patch) | |
tree | ea6f947e5d2c98a69f9db4bc0bdf089e4d22d501 | |
parent | 2958b0c474a3104174e15e17df16ced61b9d72a7 (diff) | |
download | caddy-898ef9f212b768e12cd95af897e46d7896950aeb.tar.gz caddy-898ef9f212b768e12cd95af897e46d7896950aeb.zip |
encode: flush already compressed data from the encoder (#6471)
-rw-r--r-- | modules/caddyhttp/encode/encode.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/modules/caddyhttp/encode/encode.go b/modules/caddyhttp/encode/encode.go index dc35fa245..e2649031b 100644 --- a/modules/caddyhttp/encode/encode.go +++ b/modules/caddyhttp/encode/encode.go @@ -212,6 +212,14 @@ func (rw *responseWriter) Flush() { // to rw.Write (see bug in #4314) return } + // also flushes the encoder, if any + // see: https://github.com/jjiang-stripe/caddy-slow-gzip + if rw.w != nil { + err := rw.w.Flush() + if err != nil { + return err + } + } //nolint:bodyclose http.NewResponseController(rw.ResponseWriter).Flush() } @@ -408,6 +416,7 @@ type encodingPreference struct { type Encoder interface { io.WriteCloser Reset(io.Writer) + Flush() error // encoder by default buffers data to maximize compressing rate } // Encoding is a type which can create encoders of its kind |