@@ -260,23 +260,6 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
260
260
netDial = (& net.Dialer {}).DialContext
261
261
}
262
262
263
- // If needed, wrap the dial function to set the connection deadline.
264
- if deadline , ok := ctx .Deadline (); ok {
265
- forwardDial := netDial
266
- netDial = func (ctx context.Context , network , addr string ) (net.Conn , error ) {
267
- c , err := forwardDial (ctx , network , addr )
268
- if err != nil {
269
- return nil , err
270
- }
271
- err = c .SetDeadline (deadline )
272
- if err != nil {
273
- c .Close ()
274
- return nil , err
275
- }
276
- return c , nil
277
- }
278
- }
279
-
280
263
// If needed, wrap the dial function to connect through a proxy.
281
264
if d .Proxy != nil {
282
265
proxyURL , err := d .Proxy (req )
@@ -305,6 +288,23 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
305
288
}
306
289
}
307
290
291
+ // If needed, wrap the dial function to set the connection deadline.
292
+ if deadline , ok := ctx .Deadline (); ok {
293
+ forwardDial := netDial
294
+ netDial = func (ctx context.Context , network , addr string ) (net.Conn , error ) {
295
+ c , err := forwardDial (ctx , network , addr )
296
+ if err != nil {
297
+ return nil , err
298
+ }
299
+ err = c .SetDeadline (deadline )
300
+ if err != nil {
301
+ c .Close ()
302
+ return nil , err
303
+ }
304
+ return c , nil
305
+ }
306
+ }
307
+
308
308
hostPort , hostNoPort := hostPortNoPort (u )
309
309
trace := httptrace .ContextClientTrace (ctx )
310
310
if trace != nil && trace .GetConn != nil {
0 commit comments