Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fabio does not serve http2 with go >= 1.7 #215

Closed
smancke opened this issue Jan 16, 2017 · 11 comments
Closed

Fabio does not serve http2 with go >= 1.7 #215

smancke opened this issue Jan 16, 2017 · 11 comments
Labels
Milestone

Comments

@smancke
Copy link
Contributor

smancke commented Jan 16, 2017

We found out, that fabio currently is not doing http2.
The reasons seems to be a change in go's behavior, when you supply a custom tls.Config (see golang/go#15908).
Before 1.7 it was fine to have NextProtos: nil, now it has to be set explicitly. NextProtos: []string{"h2"}.
The same thing hit the caddy server (see caddyserver/caddy#976).

When I add

	x := &tls.Config{
		NextProtos: []string{"h2"},

in cert/source.go it has http support. This seems to be consistent to the documentation of the method shouldConfigureHTTP2ForServe() in net/http/server.

magiconair added a commit that referenced this issue Jan 16, 2017
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
@magiconair
Copy link
Contributor

@smancke like this?

@smancke
Copy link
Contributor Author

smancke commented Jan 16, 2017

@magiconair yes

@magiconair
Copy link
Contributor

I'm trying to see an HTTP/2 request in the testSource() function in cert/source_test.go but I don't see it. Trying to print the proto and somehow expecting HTTP/2 here:

srv := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	fmt.Println("Proto:", r.Proto)
	fmt.Fprint(w, "OK")
}))

Any idea what I'm missing?

@smancke
Copy link
Contributor Author

smancke commented Jan 16, 2017

the go http client does not do http2 by default, if you configure it with a custom tls config:

in net/http/transport.go

func (t *Transport) onceSetNextProtoDefaults() {
...
	if t.TLSClientConfig != nil || t.Dial != nil || t.DialTLS != nil {
		// Be conservative and don't automatically enable
		// http2 if they've specified a custom TLS config or
		// custom dialers. Let them opt-in themselves via
		// http2.ConfigureTransport so we don't surprise them
		// by modifying their tls.Config. Issue 14275.
		return
	}
...
}

There must be a way to force the transport by hand, but I don't found how ..

@smancke
Copy link
Contributor Author

smancke commented Jan 16, 2017

@magiconair
This works for configuring the client, using the golang/x http2 package:

      import "golang.org/x/net/http2"

	clientTransport := &http.Transport{
		TLSClientConfig: &tls.Config{
			RootCAs: rootCAs,
		},
	}
	http2.ConfigureTransport(clientTransport)
	client := http.Client{
		Transport: clientTransport,
	}

Proto: HTTP/2.0

magiconair added a commit that referenced this issue Jan 16, 2017
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
@magiconair
Copy link
Contributor

@smancke Awesome. Thanks a lot. I've updated the change to include the test. Testing for HTTP/2 feels grafted on though. Maybe its better to move this to a separate test but for now at least there is a test.

@smancke
Copy link
Contributor Author

smancke commented Jan 16, 2017

Cool!!
Any idea, when this will be in a release?

magiconair added a commit that referenced this issue Jan 16, 2017
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
magiconair added a commit that referenced this issue Jan 16, 2017
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
@magiconair magiconair added the bug label Jan 16, 2017
@magiconair
Copy link
Contributor

@smancke I can spin a 1.3.6 tomorrow. Also, time to wrap up the other lingering changes. Quick enough?

@smancke
Copy link
Contributor Author

smancke commented Jan 16, 2017

Yes, would be very great!
Thanks a lot!!

@magiconair
Copy link
Contributor

Thanks for finding and helping! Appreciated.

magiconair added a commit that referenced this issue Jan 17, 2017
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
magiconair added a commit that referenced this issue Jan 17, 2017
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
@magiconair magiconair added this to the 1.3.6 milestone Jan 17, 2017
@magiconair
Copy link
Contributor

Merged to master and published in 1.3.6 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants