Skip to content

Update Conn.Close docs #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion statuscode.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const (
)

// CloseError represents a WebSocket close frame.
// It is returned by Conn's methods when the Connection is closed with a WebSocket close frame.
// It is returned by Conn's methods when a WebSocket close frame is received from
// the peer.
// You will need to use https://golang.org/x/xerrors to check for this error.
type CloseError struct {
Code StatusCode
Expand Down
7 changes: 6 additions & 1 deletion websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,9 @@ func (c *Conn) writePong(p []byte) error {
// The connection can only be closed once. Additional calls to Close
// are no-ops.
//
// This does not perform a WebSocket close handshake.
// See https://github.com/nhooyr/websocket/issues/103 for details on why.
//
// The maximum length of reason must be 125 bytes otherwise an internal
// error will be sent to the peer. For this reason, you should avoid
// sending a dynamic reason.
Expand Down Expand Up @@ -823,7 +826,9 @@ func (c *Conn) exportedClose(code StatusCode, reason string) error {
p, _ = ce.bytes()
}

err = c.writeClose(p, xerrors.Errorf("sent close frame: %w", ce))
// CloseErrors sent are made opaque to prevent applications from thinking
// they received a given status.
err = c.writeClose(p, xerrors.Errorf("sent close frame: %v", ce))
if err != nil {
return err
}
Expand Down