From 1beab906a9fa3c9e3f1871deced6cb4a42429c20 Mon Sep 17 00:00:00 2001 From: peanutzhen Date: Fri, 11 Feb 2022 15:59:25 +0800 Subject: [PATCH] fix nil pointer --- stream.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stream.go b/stream.go index fff68a5..759180d 100644 --- a/stream.go +++ b/stream.go @@ -81,6 +81,7 @@ func handleHttp(c2s, s2c io.Reader) { c2sReader := bufio.NewReader(c2s) s2cReader := bufio.NewReader(s2c) for { + // read http request and response. req, err := http.ReadRequest(c2sReader) if err == io.EOF || err == io.ErrUnexpectedEOF { break @@ -96,6 +97,7 @@ func handleHttp(c2s, s2c io.Reader) { continue } + // send http req/resp to bubblereplay. err = sendReqResp(req, resp) if err != nil { logrus.Errorf("send old req/resp failed, %s", err) @@ -137,7 +139,6 @@ func sendReqResp(req *http.Request, resp *http.Response) (err error) { api := fmt.Sprintf("http://%s%s", configuration.ReplaySvrAddr, ApiAddRecord) apiResp, err := http.Post(api, "application/octet-stream", bytes.NewReader(rawpb)) - defer apiResp.Body.Close() if err != nil { return err } @@ -155,5 +156,5 @@ func sendReqResp(req *http.Request, resp *http.Response) (err error) { return errors.New(response.Msg) } - return nil + return apiResp.Body.Close() }