mirror of
https://github.com/caddyserver/caddy.git
synced 2025-02-13 03:26:37 +01:00
encode: write status immediately when status code is informational (#6164)
This commit is contained in:
parent
c27425ef5d
commit
e698ec5139
1 changed files with 6 additions and 15 deletions
|
@ -20,11 +20,9 @@
|
||||||
package encode
|
package encode
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"net"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -221,6 +219,12 @@ type responseWriter struct {
|
||||||
// to actually write the header.
|
// to actually write the header.
|
||||||
func (rw *responseWriter) WriteHeader(status int) {
|
func (rw *responseWriter) WriteHeader(status int) {
|
||||||
rw.statusCode = status
|
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.
|
// Match determines, if encoding should be done based on the ResponseMatcher.
|
||||||
|
@ -242,19 +246,6 @@ func (rw *responseWriter) Flush() {
|
||||||
http.NewResponseController(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,
|
// Write writes to the response. If the response qualifies,
|
||||||
// it is encoded using the encoder, which is initialized
|
// it is encoded using the encoder, which is initialized
|
||||||
// if not done so already.
|
// if not done so already.
|
||||||
|
|
Loading…
Reference in a new issue