Skip to content

Commit

Permalink
Issue #215: Re-enable HTTP/2 support
Browse files Browse the repository at this point in the history
This patch re-enables the HTTP/2 support
for go1.7 and beyond by setting the NextProto
field in the custom TLSConfig.

See golang/go#15908
  • Loading branch information
magiconair committed Jan 16, 2017
1 parent d345f02 commit 056a09e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions cert/source.go
Expand Up @@ -87,6 +87,7 @@ func TLSConfig(src Source, strictMatch bool) (*tls.Config, error) {

store := NewStore()
x := &tls.Config{
NextProtos: []string{"h2"},
GetCertificate: func(clientHello *tls.ClientHelloInfo) (cert *tls.Certificate, err error) {
return getCertificate(store.certstore(), clientHello, strictMatch)
},
Expand Down
18 changes: 10 additions & 8 deletions cert/source_test.go
Expand Up @@ -21,6 +21,8 @@ import (
"testing"
"time"

"golang.org/x/net/http2"

"github.com/eBay/fabio/config"
consulapi "github.com/hashicorp/consul/api"
vaultapi "github.com/hashicorp/vault/api"
Expand Down Expand Up @@ -388,22 +390,22 @@ func testSource(t *testing.T, source Source, rootCAs *x509.CertPool, sleep time.
// create the https server and start it
// it will be listening on 127.0.0.1
srv := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "OK")
fmt.Fprint(w, "OK ", r.Proto)
}))
srv.TLS = srvConfig
srv.StartTLS()
defer srv.Close()

// create an http client that will accept the root CAs
// create an HTTP/2 client that will accept the root CAs
// otherwise the HTTPS client will not verify the
// certificate presented by the server.
client := http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: rootCAs,
},
clientTransport := &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: rootCAs,
},
}
http2.ConfigureTransport(clientTransport)
client := http.Client{Transport: clientTransport}

call := func(host string) (statusCode int, body string, err error) {
// for the certificate validation to work we need to use a hostname
Expand Down Expand Up @@ -444,7 +446,7 @@ func testSource(t *testing.T, source Source, rootCAs *x509.CertPool, sleep time.
if got, want := statusCode, 200; got != want {
t.Fatalf("got %v want %v", got, want)
}
if got, want := body, "OK"; got != want {
if got, want := body, "OK HTTP/2.0"; got != want {
t.Fatalf("got %v want %v", got, want)
}
}
Expand Down

0 comments on commit 056a09e

Please sign in to comment.