[go] net/http: change Transport.Dialer to Transport.DialContext

678 views
Skip to first unread message

Russ Cox (Gerrit)

unread,
May 27, 2016, 11:16:57 AM5/27/16
to Dan Peterson, Ian Lance Taylor, Russ Cox, golang-co...@googlegroups.com
Reviewers: Dan Peterson, Ian Lance Taylor

Russ Cox uploaded a change:
https://go-review.googlesource.com/23489

net/http: change Transport.Dialer to Transport.DialContext

New in Go 1.7 so still possible to change.
This allows implementations not tied to *net.Dialer.

Fixes #15748.

Change-Id: I5fabbf13c7f1951c06587a4ccd120def488267ce
---
M src/net/http/transport.go
1 file changed, 14 insertions(+), 14 deletions(-)



diff --git a/src/net/http/transport.go b/src/net/http/transport.go
index 57ebbd5..43b20f2 100644
--- a/src/net/http/transport.go
+++ b/src/net/http/transport.go
@@ -37,10 +37,10 @@
// $no_proxy) environment variables.
var DefaultTransport RoundTripper = &Transport{
Proxy: ProxyFromEnvironment,
- Dialer: &net.Dialer{
+ DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
- },
+ }).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
@@ -87,17 +87,17 @@
// If Proxy is nil or returns a nil *URL, no proxy is used.
Proxy func(*Request) (*url.URL, error)

- // Dial specifies the dial function for creating unencrypted
- // TCP connections. If Dial and Dialer are both nil, net.Dial
- // is used.
- //
- // Deprecated: Use Dialer instead. If both are specified, Dialer
- // takes precedence.
- Dial func(network, addr string) (net.Conn, error)
+ // DialContext specifies the dial function for creating unencrypted TCP
connections.
+ // If DialContext is nil (and the deprecated Dial below is also nil),
+ // then the transport dials using package net.
+ DialContext func(ctx context.Context, network, addr string) (net.Conn,
error)

- // Dialer optionally specifies a dialer configuration to use
- // for new connections.
- Dialer *net.Dialer
+ // Dial specifies the dial function for creating unencrypted TCP
connections.
+ //
+ // Deprecated: Use DialContext instead, which allows the transport
+ // to cancel dials as soon as they are no longer needed.
+ // If both are set, DialContext takes priority.
+ Dial func(network, addr string) (net.Conn, error)

// DialTLS specifies an optional dial function for creating
// TLS connections for non-proxied HTTPS requests.
@@ -777,8 +777,8 @@
var zeroDialer net.Dialer

func (t *Transport) dial(ctx context.Context, network, addr string)
(net.Conn, error) {
- if t.Dialer != nil {
- return t.Dialer.DialContext(ctx, network, addr)
+ if t.DialContext != nil {
+ return t.DialContext(ctx, network, addr)
}
if t.Dial != nil {
c, err := t.Dial(network, addr)

--
https://go-review.googlesource.com/23489
Gerrit-Reviewer: Dan Peterson <dpi...@gmail.com>
Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
Gerrit-Reviewer: Russ Cox <r...@golang.org>

Gobot Gobot (Gerrit)

unread,
May 27, 2016, 11:17:55 AM5/27/16
to Russ Cox, Ian Lance Taylor, Dan Peterson, golang-co...@googlegroups.com
Gobot Gobot has posted comments on this change.

net/http: change Transport.Dialer to Transport.DialContext

Patch Set 1:

TryBots beginning. Status page: http://farmer.golang.org/try?commit=b0d74c34

--
https://go-review.googlesource.com/23489
Gerrit-Reviewer: Dan Peterson <dpi...@gmail.com>
Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-HasComments: No

Gobot Gobot (Gerrit)

unread,
May 27, 2016, 11:28:04 AM5/27/16
to Russ Cox, Ian Lance Taylor, Dan Peterson, golang-co...@googlegroups.com
Gobot Gobot has posted comments on this change.

net/http: change Transport.Dialer to Transport.DialContext

Patch Set 1: TryBot-Result+1

TryBots are happy.

--
https://go-review.googlesource.com/23489
Gerrit-Reviewer: Dan Peterson <dpi...@gmail.com>
Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-HasComments: No

Ian Lance Taylor (Gerrit)

unread,
May 27, 2016, 11:47:13 AM5/27/16
to Russ Cox, Gobot Gobot, Dan Peterson, golang-co...@googlegroups.com
Ian Lance Taylor has posted comments on this change.

net/http: change Transport.Dialer to Transport.DialContext

Patch Set 2: Code-Review+2

--
https://go-review.googlesource.com/23489
Gerrit-Reviewer: Dan Peterson <dpi...@gmail.com>
Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-HasComments: No

Russ Cox (Gerrit)

unread,
May 27, 2016, 12:26:45 PM5/27/16
to Russ Cox, golang-...@googlegroups.com, Gobot Gobot, Ian Lance Taylor, Dan Peterson, golang-co...@googlegroups.com
Russ Cox has submitted this change and it was merged.

net/http: change Transport.Dialer to Transport.DialContext

New in Go 1.7 so still possible to change.
This allows implementations not tied to *net.Dialer.

Fixes #15748.

Change-Id: I5fabbf13c7f1951c06587a4ccd120def488267ce
Reviewed-on: https://go-review.googlesource.com/23489
Reviewed-by: Ian Lance Taylor <ia...@golang.org>
---
M src/net/http/transport.go
1 file changed, 14 insertions(+), 14 deletions(-)

Approvals:
Ian Lance Taylor: Looks good to me, approved


--
https://go-review.googlesource.com/23489
Gerrit-Reviewer: Dan Peterson <dpi...@gmail.com>
Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
Reply all
Reply to author
Forward
0 new messages