Skip to content

Commit

Permalink
Silence false positive lint warning in proxy code
Browse files Browse the repository at this point in the history
  • Loading branch information
Canelo Hill authored and jaitaiwan committed Jun 19, 2024
1 parent f78ed9f commit 1cb401f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package websocket

import (
"bufio"
"bytes"
"context"
"encoding/base64"
"errors"
"net"
Expand Down Expand Up @@ -68,8 +70,18 @@ func (hpd *httpProxyDialer) Dial(network string, addr string) (net.Conn, error)
return nil, err
}

if resp.StatusCode != 200 {
conn.Close()
// Close the response body to silence false positives from linters. Reset
// 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)
return nil, errors.New(f[1])
}
Expand Down

0 comments on commit 1cb401f

Please sign in to comment.