Skip to content

Commit caa434d

Browse files
committed
net/http: update Transport doc example to not disable http2
The old Transport example ended up disabling HTTP/2. Use a better example. Fixes #17051 Fixes #17296 Change-Id: I6feca168744131916e8bf56c829b4d4b50e304ee Reviewed-on: https://go-review.googlesource.com/33094 Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent b20c055 commit caa434d

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/net/http/doc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ For control over proxies, TLS configuration, keep-alives,
4444
compression, and other settings, create a Transport:
4545
4646
tr := &http.Transport{
47-
TLSClientConfig: &tls.Config{RootCAs: pool},
47+
MaxIdleConns: 10,
48+
IdleConnTimeout: 30 * time.Second,
4849
DisableCompression: true,
4950
}
5051
client := &http.Client{Transport: tr}

src/net/http/transport.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ const DefaultMaxIdleConnsPerHost = 2
6868
// For high-level functionality, such as cookies and redirects, see Client.
6969
//
7070
// Transport uses HTTP/1.1 for HTTP URLs and either HTTP/1.1 or HTTP/2
71-
// for HTTPS URLs, depending on whether the server supports HTTP/2.
72-
// See the package docs for more about HTTP/2.
71+
// for HTTPS URLs, depending on whether the server supports HTTP/2,
72+
// and how the Transport is configured. The DefaultTransport supports HTTP/2.
73+
// To explicitly enable HTTP/2 on a transport, use golang.org/x/net/http2
74+
// and call ConfigureTransport. See the package docs for more about HTTP/2.
7375
type Transport struct {
7476
idleMu sync.Mutex
7577
wantIdle bool // user has requested to close all idle conns
@@ -113,7 +115,9 @@ type Transport struct {
113115
DialTLS func(network, addr string) (net.Conn, error)
114116

115117
// TLSClientConfig specifies the TLS configuration to use with
116-
// tls.Client. If nil, the default configuration is used.
118+
// tls.Client.
119+
// If nil, the default configuration is used.
120+
// If non-nil, HTTP/2 support may not be enabled by default.
117121
TLSClientConfig *tls.Config
118122

119123
// TLSHandshakeTimeout specifies the maximum amount of time waiting to
@@ -172,7 +176,8 @@ type Transport struct {
172176
// called with the request's authority (such as "example.com"
173177
// or "example.com:1234") and the TLS connection. The function
174178
// must return a RoundTripper that then handles the request.
175-
// If TLSNextProto is nil, HTTP/2 support is enabled automatically.
179+
// If TLSNextProto is not nil, HTTP/2 support is not enabled
180+
// automatically.
176181
TLSNextProto map[string]func(authority string, c *tls.Conn) RoundTripper
177182

178183
// ProxyConnectHeader optionally specifies headers to send to

0 commit comments

Comments
 (0)