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 <wofwca@protonmail.com>
This commit is contained in:
WofWca 2024-11-16 13:08:53 +00:00 committed by GitHub
parent 5e00238113
commit 1efee6b4af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 1 deletions

View File

@ -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 {