Silence false positive lint warning in proxy code

This commit is contained in:
Canelo Hill 2024-06-14 10:51:13 -07:00 committed by Daniel Holmes
parent f78ed9f987
commit 70bf50955e
1 changed files with 13 additions and 2 deletions

View File

@ -6,6 +6,7 @@ package websocket
import ( import (
"bufio" "bufio"
"bytes"
"encoding/base64" "encoding/base64"
"errors" "errors"
"net" "net"
@ -68,8 +69,18 @@ func (hpd *httpProxyDialer) Dial(network string, addr string) (net.Conn, error)
return nil, err return nil, err
} }
if resp.StatusCode != 200 { // Close the response body to silence false positives from linters. Reset
conn.Close() // the buffered reader first to ensure that Close() does not read from
// conn.
// Note: Applications must call resp.Body.Close() on a response returned
// http.ReadResponse to inspect trailers or read another response from the
// buffered reader. The call to resp.Body.Close() does not release
// resources.
br.Reset(bytes.NewReader(nil))
_ = resp.Body.Close()
if resp.StatusCode != http.StatusOK {
_ = conn.Close()
f := strings.SplitN(resp.Status, " ", 2) f := strings.SplitN(resp.Status, " ", 2)
return nil, errors.New(f[1]) return nil, errors.New(f[1])
} }