From 1efee6b4af113e2abc2dc2176698a2612f31d4b5 Mon Sep 17 00:00:00 2001 From: WofWca Date: Sat, 16 Nov 2024 13:08:53 +0000 Subject: [PATCH] docs: client: clarify handshake error conditions The purpose of this change is to set this behavior in stone, so that, for example, introducing "follow redirects" by default would be a breaking change. The [WebSocket spec](https://www.rfc-editor.org/rfc/rfc6455) actually allows the client to follow redirects: > the server might redirect the client using a 3xx status code (but clients are not required to follow them) I think this library should be explicit about whether it does this. I feel like the existing "...so that callers can handle redirects, authentication, etcetera" is not worded strongly enough. Signed-off-by: WofWca --- client.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 24bd7ff..ac12933 100644 --- a/client.go +++ b/client.go @@ -34,6 +34,7 @@ var errInvalidCompression = errors.New("websocket: invalid compression negotiati // If the WebSocket handshake fails, ErrBadHandshake is returned along with a // non-nil *http.Response so that callers can handle redirects, authentication, // etc. +// All non-101 response codes result in an error. // // Deprecated: Use Dialer instead. func NewClient(netConn net.Conn, u *url.URL, requestHeader http.Header, readBufSize, writeBufSize int) (c *Conn, response *http.Response, err error) { @@ -154,7 +155,9 @@ var nilDialer = *DefaultDialer // // If the WebSocket handshake fails, ErrBadHandshake is returned along with a // non-nil *http.Response so that callers can handle redirects, authentication, -// etcetera. The response body may not contain the entire response and does not +// etcetera. +// All non-101 response codes result in an error. +// The response body may not contain the entire response and does not // need to be closed by the application. func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader http.Header) (*Conn, *http.Response, error) { if d == nil {