Buffer http response instead of writing directly (#106)

This commit is contained in:
Mygod 2023-05-29 01:42:55 -04:00 committed by GitHub
parent 685d1d0d78
commit 8b5d75a979
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -590,7 +590,13 @@ func serveHijack(w http.ResponseWriter, targetConn net.Conn) error {
}
res.Header.Set("Server", "Caddy")
err = res.Write(clientConn)
buf := bufio.NewWriter(clientConn)
err = res.Write(buf)
if err != nil {
return caddyhttp.Error(http.StatusInternalServerError,
fmt.Errorf("failed to write response: %v", err))
}
err = buf.Flush()
if err != nil {
return caddyhttp.Error(http.StatusInternalServerError,
fmt.Errorf("failed to send response to client: %v", err))