Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 13, 05:30 UTC
encode: flush status code when hijacked. (#5419)
WeidiDeng committed
Mar 7, 2023 at 00:13 UTC
b3f0cea2c31f6137cd1604ba31afffdbfc8b70ee
1 file changed
+14
modules/caddyhttp/encode/encode.go
+14
@@ -20,9 +20,11 @@
20
package encode
21
22
import (
23
+ "bufio"
24
"fmt"
25
"io"
26
"math"
27
+ "net"
28
"net/http"
29
"sort"
30
"strconv"
@@ -212,6 +214,18 @@ func (rw *responseWriter) Flush() {
214
rw.HTTPInterfaces.Flush()
215
}
216
217
+// Hijack implements http.Hijacker. It will flush status code if set. We don't track actual hijacked
218
+// status assuming http middlewares will track its status.
219
+func (rw *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
220
+ if !rw.wroteHeader {
221
+ if rw.statusCode != 0 {
222
+ rw.HTTPInterfaces.WriteHeader(rw.statusCode)
223
+ }
224
+ rw.wroteHeader = true
225
+ }
226
+ return rw.HTTPInterfaces.Hijack()
227
+}
228
+
229
// Write writes to the response. If the response qualifies,
230
// it is encoded using the encoder, which is initialized
231
// if not done so already.