88 "context"
99 "crypto/rand"
1010 "encoding/base64"
11- "errors"
1211 "fmt"
1312 "io"
1413 "io/ioutil"
@@ -26,6 +25,7 @@ type DialOptions struct {
2625 // HTTPClient is used for the connection.
2726 // Its Transport must return writable bodies for WebSocket handshakes.
2827 // http.Transport does beginning with Go 1.12.
28+ // Non-zero timeout will be ignored, see https://github.com/nhooyr/websocket/issues/67.
2929 HTTPClient * http.Client
3030
3131 // HTTPHeader specifies the HTTP headers included in the handshake request.
@@ -74,7 +74,15 @@ func dial(ctx context.Context, urls string, opts *DialOptions, rand io.Reader) (
7474 opts = & * opts
7575 if opts .HTTPClient == nil {
7676 opts .HTTPClient = http .DefaultClient
77+ } else if opts .HTTPClient .Timeout > 0 {
78+ // remove timeout
79+ opts .HTTPClient = & http.Client {
80+ Transport : opts .HTTPClient .Transport ,
81+ CheckRedirect : opts .HTTPClient .CheckRedirect ,
82+ Jar : opts .HTTPClient .Jar ,
83+ }
7784 }
85+
7886 if opts .HTTPHeader == nil {
7987 opts .HTTPHeader = http.Header {}
8088 }
@@ -133,10 +141,6 @@ func dial(ctx context.Context, urls string, opts *DialOptions, rand io.Reader) (
133141}
134142
135143func handshakeRequest (ctx context.Context , urls string , opts * DialOptions , copts * compressionOptions , secWebSocketKey string ) (* http.Response , error ) {
136- if opts .HTTPClient .Timeout > 0 {
137- return nil , errors .New ("use context for cancellation instead of http.Client.Timeout; see https://github.com/nhooyr/websocket/issues/67" )
138- }
139-
140144 u , err := url .Parse (urls )
141145 if err != nil {
142146 return nil , fmt .Errorf ("failed to parse url: %w" , err )
0 commit comments