Skip to content

net/http: Go 1.6 http.Client doesn't support http2 by default #14391

Closed
@kron4eg

Description

@kron4eg
go version go1.6 darwin/amd64

It's said in documentation that http2 is enabled by default in release 1.6 for server and client, but client refuses to communicate http2.

package main

import (
    "fmt"
    "io/ioutil"
    "log"
    "net/http"
)

func main() {
    response, err := http.Get("https://http2.golang.org/reqinfo")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("is HTTP2: %v (%s)\n\n", response.ProtoAtLeast(2, 0), response.Proto)
    body, err := ioutil.ReadAll(response.Body)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(string(body))
}

returns

is HTTP2: false (HTTP/1.1)

Method: GET
Protocol: HTTP/1.1
Host: http2.golang.org
RemoteAddr: REMOVED:33882
RequestURI: "/reqinfo"
URL: &url.URL{Scheme:"", Opaque:"", User:(*url.Userinfo)(nil), Host:"", Path:"/reqinfo", RawPath:"", RawQuery:"", Fragment:""}
Body.ContentLength: 0 (-1 means unknown)
Close: false (relevant for HTTP/1 only)
TLS: &tls.ConnectionState{Version:0x303, HandshakeComplete:true, DidResume:false, CipherSuite:0xc02f, NegotiatedProtocol:"", NegotiatedProtocolIsMutual:true, ServerName:"http2.golang.org", PeerCertificates:[]*x509.Certificate(nil), VerifiedChains:[][]*x509.Certificate(nil), SignedCertificateTimestamps:[][]uint8(nil), OCSPResponse:[]uint8(nil), TLSUnique:[]uint8{0xcf, 0x67, 0x6b, 0xfb, 0x3c, 0xc2, 0xc6, 0xc2, 0xb9, 0xfb, 0x1b, 0x24}}

Headers:
Accept-Encoding: gzip
User-Agent: Go-http-client/1.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions