From d43a1f8494e2f24f6ec4bb6d197e62c18c5bb25b Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Wed, 23 May 2018 11:21:08 +0800 Subject: [PATCH] reply a error when connect to http backend error --- handler.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/handler.go b/handler.go index f29078f..88baa4c 100644 --- a/handler.go +++ b/handler.go @@ -112,6 +112,7 @@ func handleForward(c *tls.Conn, b *url.URL) { remote, err = net.Dial("tcp", b.Host) if err != nil { log.Printf("dial to %s error: %s", b.Host, err) + writeErrResponse(c, http.StatusBadGateway, err.Error()) return } httpForward(c, remote) @@ -136,11 +137,13 @@ func handleForward(c *tls.Conn, b *url.URL) { //log.Println("begin data forward") defer remote.Close() + ch := make(chan struct{}, 2) go func() { io.Copy(c, remote) ch <- struct{}{} }() + go func() { io.Copy(remote, c) ch <- struct{}{}