diff options
author | WeidiDeng <[email protected]> | 2024-03-10 22:49:49 +0800 |
---|---|---|
committer | GitHub <[email protected]> | 2024-03-10 10:49:49 -0400 |
commit | e698ec5139e94de4702ebd7530546e16393638b9 (patch) | |
tree | b4187bb6a2ac9be210f8068077c77c030decd46e | |
parent | c27425ef5d112bb71e8b7bf4abfb73464fbf869a (diff) | |
download | caddy-e698ec5139e94de4702ebd7530546e16393638b9.tar.gz caddy-e698ec5139e94de4702ebd7530546e16393638b9.zip |
encode: write status immediately when status code is informational (#6164)
-rw-r--r-- | modules/caddyhttp/encode/encode.go | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/modules/caddyhttp/encode/encode.go b/modules/caddyhttp/encode/encode.go index bd3d84bc8..91f25294f 100644 --- a/modules/caddyhttp/encode/encode.go +++ b/modules/caddyhttp/encode/encode.go @@ -20,11 +20,9 @@ package encode import ( - "bufio" "fmt" "io" "math" - "net" "net/http" "sort" "strconv" @@ -221,6 +219,12 @@ type responseWriter struct { // to actually write the header. func (rw *responseWriter) WriteHeader(status int) { rw.statusCode = status + + // write status immediately when status code is informational + // see: https://caddy.community/t/disappear-103-early-hints-response-with-encode-enable-caddy-v2-7-6/23081/5 + if 100 <= status && status <= 199 { + rw.ResponseWriter.WriteHeader(status) + } } // Match determines, if encoding should be done based on the ResponseMatcher. @@ -242,19 +246,6 @@ func (rw *responseWriter) Flush() { http.NewResponseController(rw.ResponseWriter).Flush() } -// Hijack implements http.Hijacker. It will flush status code if set. We don't track actual hijacked -// status assuming http middlewares will track its status. -func (rw *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { - if !rw.wroteHeader { - if rw.statusCode != 0 { - rw.ResponseWriter.WriteHeader(rw.statusCode) - } - rw.wroteHeader = true - } - //nolint:bodyclose - return http.NewResponseController(rw.ResponseWriter).Hijack() -} - // Write writes to the response. If the response qualifies, // it is encoded using the encoder, which is initialized // if not done so already. |