title: How to force client to use http/2? (instead of falling back to http 1.1)
body: <p>How can I force a simple Go client to use HTTP/2 and prevent it from falling back to HTTP 1.1 ?</p>
  
  <p>I have a simple HTTP/2 server running on "localhost" and it returns details of the request in its reply.  Here is the output using Google Chrome for this URL: <a href="https://localhost:40443/bananas" rel="nofollow noreferrer">https://localhost:40443/bananas</a></p>
  
  <pre><code>I like bananas!
  Method       = GET
  URL          = /bananas
  Proto        = HTTP/2.0
  Host         = localhost:40443
  RequestURI   = /bananas
  </code></pre>
  
  <p>But here is what I get for my Go client code.  You can see it falls back to HTTP 1.1</p>
  
  <pre><code>I like monkeys!
  Method       = GET
  URL          = /monkeys
  Proto        = HTTP/1.1
  Host         = localhost:40443
  RequestURI   = /monkeys
  </code></pre>
  
  <p>Below is the source code of my best attempt to contact the same server using HTTP/2, but it always falls back to HTTP 1.1</p>
  
  <pre><code>// simple http/2 client
  
  package main
  
  import (
      "crypto/tls"
      "crypto/x509"
      "fmt"
      "io/ioutil"
      "log"
      "net/http"
  )
  
  const (
      certFile = "client-cert.pem"
      keyFile  = "client-key.pem"
      caFile   = "server-cert.pem"
  )
  
  func main() {
      // Load client certificate
      cert, err := tls.LoadX509KeyPair(certFile, keyFile)
      if err != nil {
          log.Fatal(err)
      }
  
      // Load CA cert
      caCert, err := ioutil.ReadFile(caFile)
      if err != nil {
          log.Fatal(err)
      }
      caCertPool := x509.NewCertPool()
      caCertPool.AppendCertsFromPEM(caCert)
  
      // Setup HTTPS client
      tlsConfig := &amp;tls.Config{
          Certificates: []tls.Certificate{cert},
          RootCAs:      caCertPool,
      }
      tlsConfig.BuildNameToCertificate()
      transport := &amp;http.Transport{TLSClientConfig: tlsConfig}
      client := &amp;http.Client{Transport: transport}
  
      response, err := client.Get("https://localhost:40443/monkeys")
      if err != nil {
          log.Fatal(err)
      }
      defer response.Body.Close()
  
      // dump response
      text, err := ioutil.ReadAll(response.Body)
      if err != nil {
          log.Fatal(err)
      }
      fmt.Printf("Body:\n%s", text)
  }
  </code></pre>
  
  <p>Any suggestions would be appreciated, including pointers to other working examples that illustrate how to make HTTP/2 client requests in Go.</p>