From 29bba1ad6ceb7e6a2d86b10e694eb0cb2f846415 Mon Sep 17 00:00:00 2001 From: Cooper Oh Date: Thu, 18 Jul 2024 21:34:27 +0900 Subject: [PATCH] move connection deadline set below --- client.go | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/client.go b/client.go index 8666562..69347e8 100644 --- a/client.go +++ b/client.go @@ -260,23 +260,6 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h netDial = (&net.Dialer{}).DialContext } - // If needed, wrap the dial function to set the connection deadline. - if deadline, ok := ctx.Deadline(); ok { - forwardDial := netDial - netDial = func(ctx context.Context, network, addr string) (net.Conn, error) { - c, err := forwardDial(ctx, network, addr) - if err != nil { - return nil, err - } - err = c.SetDeadline(deadline) - if err != nil { - c.Close() - return nil, err - } - return c, nil - } - } - // If needed, wrap the dial function to connect through a proxy. if d.Proxy != nil { proxyURL, err := d.Proxy(req) @@ -305,6 +288,23 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h } } + // If needed, wrap the dial function to set the connection deadline. + if deadline, ok := ctx.Deadline(); ok { + forwardDial := netDial + netDial = func(ctx context.Context, network, addr string) (net.Conn, error) { + c, err := forwardDial(ctx, network, addr) + if err != nil { + return nil, err + } + err = c.SetDeadline(deadline) + if err != nil { + c.Close() + return nil, err + } + return c, nil + } + } + hostPort, hostNoPort := hostPortNoPort(u) trace := httptrace.ContextClientTrace(ctx) if trace != nil && trace.GetConn != nil {