Commit 605e751b authored by Russ Cox's avatar Russ Cox

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/23489Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 36a80c59
...@@ -37,10 +37,10 @@ import ( ...@@ -37,10 +37,10 @@ import (
// $no_proxy) environment variables. // $no_proxy) environment variables.
var DefaultTransport RoundTripper = &Transport{ var DefaultTransport RoundTripper = &Transport{
Proxy: ProxyFromEnvironment, Proxy: ProxyFromEnvironment,
Dialer: &net.Dialer{ DialContext: (&net.Dialer{
Timeout: 30 * time.Second, Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second, KeepAlive: 30 * time.Second,
}, }).DialContext,
MaxIdleConns: 100, MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second, IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second, TLSHandshakeTimeout: 10 * time.Second,
...@@ -87,18 +87,18 @@ type Transport struct { ...@@ -87,18 +87,18 @@ type Transport struct {
// If Proxy is nil or returns a nil *URL, no proxy is used. // If Proxy is nil or returns a nil *URL, no proxy is used.
Proxy func(*Request) (*url.URL, error) Proxy func(*Request) (*url.URL, error)
// Dial specifies the dial function for creating unencrypted // DialContext specifies the dial function for creating unencrypted TCP connections.
// TCP connections. If Dial and Dialer are both nil, net.Dial // If DialContext is nil (and the deprecated Dial below is also nil),
// is used. // then the transport dials using package net.
DialContext func(ctx context.Context, network, addr string) (net.Conn, error)
// Dial specifies the dial function for creating unencrypted TCP connections.
// //
// Deprecated: Use Dialer instead. If both are specified, Dialer // Deprecated: Use DialContext instead, which allows the transport
// takes precedence. // 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) Dial func(network, addr string) (net.Conn, error)
// Dialer optionally specifies a dialer configuration to use
// for new connections.
Dialer *net.Dialer
// DialTLS specifies an optional dial function for creating // DialTLS specifies an optional dial function for creating
// TLS connections for non-proxied HTTPS requests. // TLS connections for non-proxied HTTPS requests.
// //
...@@ -777,8 +777,8 @@ func (t *Transport) replaceReqCanceler(r *Request, fn func()) bool { ...@@ -777,8 +777,8 @@ func (t *Transport) replaceReqCanceler(r *Request, fn func()) bool {
var zeroDialer net.Dialer var zeroDialer net.Dialer
func (t *Transport) dial(ctx context.Context, network, addr string) (net.Conn, error) { func (t *Transport) dial(ctx context.Context, network, addr string) (net.Conn, error) {
if t.Dialer != nil { if t.DialContext != nil {
return t.Dialer.DialContext(ctx, network, addr) return t.DialContext(ctx, network, addr)
} }
if t.Dial != nil { if t.Dial != nil {
c, err := t.Dial(network, addr) c, err := t.Dial(network, addr)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment