Skip to content

net/http: Transport TLS config example does not support http2 #17051

Closed
@joneskoo

Description

@joneskoo

In https://golang.org/pkg/net/http/

For control over proxies, TLS configuration, keep-alives, compression, and other settings, create a Transport:

tr := &http.Transport{
    TLSClientConfig:    &tls.Config{RootCAs: pool},
    DisableCompression: true,
}
client := &http.Client{Transport: tr}
resp, err := client.Get("https://example.com")

If one follows this example, http2 is not supported by the client, because
http2 depends on non-nil values for the TLS config.

The documentation should reflect the best practice how to initialize tls.Config,
which in this case should include HTTP/2 support.

This is somewhat similar to #14391?

What version of Go are you using (go version)?

go version devel +7b26919 Sat Sep 10 00:35:48 2016 +0000 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/joneskoo"
GORACE=""
GOROOT="/Users/joneskoo/src/github.com/golang/go"
GOTOOLDIR="/Users/joneskoo/src/github.com/golang/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/p9/8mb6mhcx7p3br8f18crtczzw0000gn/T/go-build695312228=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

https://play.golang.org/p/0hEow6aME1

I run this locally:

$ go run h2.go|grep "using HTTP"

What did you expect to see?

$ go run h2.go|grep "using HTTP"
<p>Congratulations, <b>you're using HTTP/2 right now</b>.</p>

I can reproduce this if I don't set the transport for the client, which uses
the default transport.

What did you see instead?

$ go run h2.go|grep "using HTTP"
<p>Unfortunately, you're <b>not</b> using HTTP/2 right now. To do so:</p>

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions