aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules/caddyhttp/encode
diff options
context:
space:
mode:
authorWeidiDeng <[email protected]>2024-07-28 07:46:56 +0800
committerGitHub <[email protected]>2024-07-27 17:46:56 -0600
commit976469ca0dbbbd948dbfd6a4caedb1e7c914ef3d (patch)
tree515967b6a4f1e689e77e2e7809821cb146c399dd /modules/caddyhttp/encode
parent9cc26ee7bf323f5fdffdfe7349794aa320a6ce6c (diff)
downloadcaddy-976469ca0dbbbd948dbfd6a4caedb1e7c914ef3d.tar.gz
caddy-976469ca0dbbbd948dbfd6a4caedb1e7c914ef3d.zip
encode: flush already compressed data from the encoder (#6471)
Diffstat (limited to 'modules/caddyhttp/encode')
-rw-r--r--modules/caddyhttp/encode/encode.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/modules/caddyhttp/encode/encode.go b/modules/caddyhttp/encode/encode.go
index cf3d17b69..00e507277 100644
--- a/modules/caddyhttp/encode/encode.go
+++ b/modules/caddyhttp/encode/encode.go
@@ -266,6 +266,14 @@ func (rw *responseWriter) FlushError() error {
// to rw.Write (see bug in #4314)
return nil
}
+ // 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
return http.NewResponseController(rw.ResponseWriter).Flush()
}
@@ -475,6 +483,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