aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2016-11-10 21:16:31 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2016-11-10 23:15:26 +0000
commitcaa434d28063b4532bc362d50285230597d6d1f6 (patch)
tree4c3e874cb7a0bbb3c564e48e71c621ad0d2bf58e
parentb20c055230a20663c75e3099f672c15c39d46b9e (diff)
downloadgo-caa434d28063b4532bc362d50285230597d6d1f6.tar.gz
go-caa434d28063b4532bc362d50285230597d6d1f6.zip
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 <iant@golang.org>
-rw-r--r--src/net/http/doc.go3
-rw-r--r--src/net/http/transport.go13
2 files changed, 11 insertions, 5 deletions
diff --git a/src/net/http/doc.go b/src/net/http/doc.go
index 4ec8272f62..430aca5906 100644
--- a/src/net/http/doc.go
+++ b/src/net/http/doc.go
@@ -44,7 +44,8 @@ For control over proxies, TLS configuration, keep-alives,
compression, and other settings, create a Transport:
tr := &http.Transport{
- TLSClientConfig: &tls.Config{RootCAs: pool},
+ MaxIdleConns: 10,
+ IdleConnTimeout: 30 * time.Second,
DisableCompression: true,
}
client := &http.Client{Transport: tr}
diff --git a/src/net/http/transport.go b/src/net/http/transport.go
index 585765d789..e484548773 100644
--- a/src/net/http/transport.go
+++ b/src/net/http/transport.go
@@ -68,8 +68,10 @@ const DefaultMaxIdleConnsPerHost = 2
// For high-level functionality, such as cookies and redirects, see Client.
//
// Transport uses HTTP/1.1 for HTTP URLs and either HTTP/1.1 or HTTP/2
-// for HTTPS URLs, depending on whether the server supports HTTP/2.
-// See the package docs for more about HTTP/2.
+// for HTTPS URLs, depending on whether the server supports HTTP/2,
+// and how the Transport is configured. The DefaultTransport supports HTTP/2.
+// To explicitly enable HTTP/2 on a transport, use golang.org/x/net/http2
+// and call ConfigureTransport. See the package docs for more about HTTP/2.
type Transport struct {
idleMu sync.Mutex
wantIdle bool // user has requested to close all idle conns
@@ -113,7 +115,9 @@ type Transport struct {
DialTLS func(network, addr string) (net.Conn, error)
// TLSClientConfig specifies the TLS configuration to use with
- // tls.Client. If nil, the default configuration is used.
+ // tls.Client.
+ // If nil, the default configuration is used.
+ // If non-nil, HTTP/2 support may not be enabled by default.
TLSClientConfig *tls.Config
// TLSHandshakeTimeout specifies the maximum amount of time waiting to
@@ -172,7 +176,8 @@ type Transport struct {
// called with the request's authority (such as "example.com"
// or "example.com:1234") and the TLS connection. The function
// must return a RoundTripper that then handles the request.
- // If TLSNextProto is nil, HTTP/2 support is enabled automatically.
+ // If TLSNextProto is not nil, HTTP/2 support is not enabled
+ // automatically.
TLSNextProto map[string]func(authority string, c *tls.Conn) RoundTripper
// ProxyConnectHeader optionally specifies headers to send to