Skip to content

Commit ceaa4b2

Browse files
authored
Merge pull request #105 from nhooyr/close-docs
Update Conn.Close docs
2 parents d772f32 + f5b6f08 commit ceaa4b2

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

statuscode.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ const (
4141
)
4242

4343
// CloseError represents a WebSocket close frame.
44-
// It is returned by Conn's methods when the Connection is closed with a WebSocket close frame.
44+
// It is returned by Conn's methods when a WebSocket close frame is received from
45+
// the peer.
4546
// You will need to use https://golang.org/x/xerrors to check for this error.
4647
type CloseError struct {
4748
Code StatusCode

websocket.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,9 @@ func (c *Conn) writePong(p []byte) error {
792792
// The connection can only be closed once. Additional calls to Close
793793
// are no-ops.
794794
//
795+
// This does not perform a WebSocket close handshake.
796+
// See https://github.com/nhooyr/websocket/issues/103 for details on why.
797+
//
795798
// The maximum length of reason must be 125 bytes otherwise an internal
796799
// error will be sent to the peer. For this reason, you should avoid
797800
// sending a dynamic reason.
@@ -823,7 +826,9 @@ func (c *Conn) exportedClose(code StatusCode, reason string) error {
823826
p, _ = ce.bytes()
824827
}
825828

826-
err = c.writeClose(p, xerrors.Errorf("sent close frame: %w", ce))
829+
// CloseErrors sent are made opaque to prevent applications from thinking
830+
// they received a given status.
831+
err = c.writeClose(p, xerrors.Errorf("sent close frame: %v", ce))
827832
if err != nil {
828833
return err
829834
}

0 commit comments

Comments
 (0)