From f5b6f08a09a9049d99353b64a7ee4920fb436c2a Mon Sep 17 00:00:00 2001
From: Anmol Sethi <hi@nhooyr.io>
Date: Fri, 12 Jul 2019 11:45:46 -0400
Subject: [PATCH] Update Conn.Close docs

Closes #103
---
 statuscode.go | 3 ++-
 websocket.go  | 7 ++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/statuscode.go b/statuscode.go
index 661c669..42ae40c 100644
--- a/statuscode.go
+++ b/statuscode.go
@@ -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
diff --git a/websocket.go b/websocket.go
index f875a14..47db5f1 100644
--- a/websocket.go
+++ b/websocket.go
@@ -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.
@@ -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
 	}
-- 
GitLab