@marcel91200 / caddy Mirror · read-only / commits / e698ec51
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 12, 15:45 UTC

encode: write status immediately when status code is informational (#6164)

WeidiDeng committed Mar 10, 2024 at 22:49 UTC e698ec5139e94de4702ebd7530546e16393638b9
1 file changed +6 -15
modules/caddyhttp/encode/encode.go
+6 -15
@@ -20,11 +20,9 @@
20 package encode
21
22 import (
23 - "bufio"
23 "fmt"
24 "io"
25 "math"
27 - "net"
26 "net/http"
27 "sort"
28 "strconv"
@@ -221,6 +219,12 @@ type responseWriter struct {
219 // to actually write the header.
220 func (rw *responseWriter) WriteHeader(status int) {
221 rw.statusCode = status
222 +
223 + // write status immediately when status code is informational
224 + // see: https://caddy.community/t/disappear-103-early-hints-response-with-encode-enable-caddy-v2-7-6/23081/5
225 + if 100 <= status && status <= 199 {
226 + rw.ResponseWriter.WriteHeader(status)
227 + }
228 }
229
230 // Match determines, if encoding should be done based on the ResponseMatcher.
@@ -242,19 +246,6 @@ func (rw *responseWriter) Flush() {
246 http.NewResponseController(rw.ResponseWriter).Flush()
247 }
248
245 -// Hijack implements http.Hijacker. It will flush status code if set. We don't track actual hijacked
246 -// status assuming http middlewares will track its status.
247 -func (rw *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
248 - if !rw.wroteHeader {
249 - if rw.statusCode != 0 {
250 - rw.ResponseWriter.WriteHeader(rw.statusCode)
251 - }
252 - rw.wroteHeader = true
253 - }
254 - //nolint:bodyclose
255 - return http.NewResponseController(rw.ResponseWriter).Hijack()
256 -}
257 -
249 // Write writes to the response. If the response qualifies,
250 // it is encoded using the encoder, which is initialized
251 // if not done so already.