From 8b5d75a979046924384050c06bd5557fcc6b1dc0 Mon Sep 17 00:00:00 2001 From: Mygod Date: Mon, 29 May 2023 01:42:55 -0400 Subject: [PATCH] Buffer http response instead of writing directly (#106) --- forwardproxy.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/forwardproxy.go b/forwardproxy.go index 45ec450..25d8f72 100644 --- a/forwardproxy.go +++ b/forwardproxy.go @@ -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))