8
8
"context"
9
9
"crypto/rand"
10
10
"encoding/base64"
11
- "errors"
12
11
"fmt"
13
12
"io"
14
13
"io/ioutil"
@@ -26,6 +25,7 @@ type DialOptions struct {
26
25
// HTTPClient is used for the connection.
27
26
// Its Transport must return writable bodies for WebSocket handshakes.
28
27
// http.Transport does beginning with Go 1.12.
28
+ // Non-zero timeout will be ignored, see https://github.com/nhooyr/websocket/issues/67.
29
29
HTTPClient * http.Client
30
30
31
31
// 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) (
74
74
opts = & * opts
75
75
if opts .HTTPClient == nil {
76
76
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
+ }
77
84
}
85
+
78
86
if opts .HTTPHeader == nil {
79
87
opts .HTTPHeader = http.Header {}
80
88
}
@@ -133,10 +141,6 @@ func dial(ctx context.Context, urls string, opts *DialOptions, rand io.Reader) (
133
141
}
134
142
135
143
func 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
-
140
144
u , err := url .Parse (urls )
141
145
if err != nil {
142
146
return nil , fmt .Errorf ("failed to parse url: %w" , err )
0 commit comments