Skip to content

Commit

Permalink
chore: encode: use FlushError instead of Flush (#6168)
Browse files Browse the repository at this point in the history
Co-authored-by: Francis Lavoie <lavofr@gmail.com>
  • Loading branch information
WeidiDeng and francislavoie authored Mar 11, 2024
1 parent e698ec5 commit 1bd598e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions modules/caddyhttp/encode/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,18 @@ func (enc *Encode) Match(rw *responseWriter) bool {
return enc.Matcher.Match(rw.statusCode, rw.Header())
}

// Flush implements http.Flusher. It delays the actual Flush of the underlying ResponseWriterWrapper
// until headers were written.
func (rw *responseWriter) Flush() {
// FlushError is an alternative Flush returning an error. It delays the actual Flush of the underlying
// ResponseWriterWrapper until headers were written.
func (rw *responseWriter) FlushError() error {
if !rw.wroteHeader {
// flushing the underlying ResponseWriter will write header and status code,
// but we need to delay that until we can determine if we must encode and
// therefore add the Content-Encoding header; this happens in the first call
// to rw.Write (see bug in #4314)
return
return nil
}
//nolint:bodyclose
http.NewResponseController(rw.ResponseWriter).Flush()
return http.NewResponseController(rw.ResponseWriter).Flush()
}

// Write writes to the response. If the response qualifies,
Expand Down

0 comments on commit 1bd598e

Please sign in to comment.