summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWeidiDeng <weidi_deng@icloud.com>2023-03-07 00:13:48 +0800
committerGitHub <noreply@github.com>2023-03-06 09:13:48 -0700
commitb3f0cea2c31f6137cd1604ba31afffdbfc8b70ee (patch)
tree4224be767d5eda32c2624d7b4401525b8a212720
parent94d41a9d86d6ca2d2d001183a62d762ee045094f (diff)
encode: flush status code when hijacked. (#5419)
-rw-r--r--modules/caddyhttp/encode/encode.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/modules/caddyhttp/encode/encode.go b/modules/caddyhttp/encode/encode.go
index e3a6267..8a6fc10 100644
--- a/modules/caddyhttp/encode/encode.go
+++ b/modules/caddyhttp/encode/encode.go
@@ -20,9 +20,11 @@
package encode
import (
+ "bufio"
"fmt"
"io"
"math"
+ "net"
"net/http"
"sort"
"strconv"
@@ -212,6 +214,18 @@ func (rw *responseWriter) Flush() {
rw.HTTPInterfaces.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.HTTPInterfaces.WriteHeader(rw.statusCode)
+ }
+ rw.wroteHeader = true
+ }
+ return rw.HTTPInterfaces.Hijack()
+}
+
// Write writes to the response. If the response qualifies,
// it is encoded using the encoder, which is initialized
// if not done so already.