From be06ade49b85d7923867b98f9a92b3637b9e85c6 Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Wed, 23 May 2018 10:40:35 +0800 Subject: [PATCH] check error on write request/response --- handler.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/handler.go b/handler.go index ebbdc8a..e2e44d7 100644 --- a/handler.go +++ b/handler.go @@ -167,12 +167,17 @@ func httpForward(r, b net.Conn) { req.Header.Add("X-Real-Ip", addr.IP.String()) //log.Printf("%+v\n", req.Header) - req.Write(b) + err = req.Write(b) if req.Body != nil { req.Body.Close() } + if err != nil { + log.Printf("write request to backend error: %s", err) + return + } + res, err := http.ReadResponse(bb, req) if err != nil { if err != io.EOF { @@ -181,10 +186,14 @@ func httpForward(r, b net.Conn) { return } - res.Write(r) + err = res.Write(r) if res.Body != nil { res.Body.Close() } + + if err != nil { + log.Printf("write response to client error: %s", err) + } } }