-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
x/net/http2: http.Server.Serve
doesn't serve http2 traffic
#14374
Comments
Per the docs, Go doesn't enable http2 for you automatically if you've set your Server's TLSConfig.NextProtos at all. If it's non-nil, it steps out of the way and assumes you want to handle it all. And in your code, you're setting it to "http/1.1". |
Even if I removed the following line: if !strSliceContains(config.NextProtos, "http/1.1") {
config.NextProtos = append(config.NextProtos, "http/1.1")
} it's still not serving http2 traffic... |
Set The http.Server's code to auto-enable http2 needs to have a reference to the *tls.Config in order to modify it to add the NextProtos. |
That works! But why would http.Server.ListenAndServeTLS work? I follow every single line of code except https://github.com/golang/go/blob/release-branch.go1.6/src/net/http/server.go#L2245-L2279. |
Oh, that's because of Lines 2554 to 2576 in 58ec583
|
Which docs need to be clarified? What implementation needs to be adjusted a bit? |
Here: // TLSNextProto optionally specifies a function to take over
// ownership of the provided TLS connection when an NPN
// protocol upgrade has occurred. The map key is the protocol
// name negotiated. The Handler argument should be used to
// handle HTTP requests and will initialize the Request's TLS
// and RemoteAddr if not already set. The connection is
// automatically closed when the function returns.
// If TLSNextProto is nil, HTTP/2 support is enabled automatically.
TLSNextProto map[string]func(*Server, *tls.Conn, Handler) It makes it sound like TLSConfig *tls.Config // optional TLS config, used by ListenAndServeTLS and the doc for // NextProtos is a list of supported, application level protocols.
NextProtos []string We should mention Does it make sense? |
uncreativemynameis on reddit pointed out that the examples don't have http2 support since they don't pass in tlsconfig to the http server. https://www.reddit.com/r/golang/comments/4axi8q/acmewrapper_add_lets_encrypt_support_to_your_go/d15fwi3 This is the go issue: golang/go#14374 The example and readme were changed to have http2 enabled.
Agreed that this is way too magic not to be documented everywhere. For example both Serve and TLSConfig should warn you that you won't get HTTP/2 with Serve unless you set Server.TLSConfig or tls.Config.NextProtos. A colleague just tripped into this, took a while to realize it. Also because #15908 would make you assume otherwise. Should i open a documentation issue? |
@FiloSottile, closed issues aren't tracked and usually comments on closed issues aren't seen. This is more documented as of b5f0aff |
1.6
Darwin, AMD64
I'm trying to pass a tls
net.Listener
tohttp.Server.Serve
but the server didn't run on http2.See below code:
When I curled it:
I compared line by line my implementation of
listenAndServeTLS
withhttp.Sever.ListenAndServeTLS
. The difference is I didn't callsrv.setupHTTP2()
. But it should be called inhttp.Server.Serve
again. However, if I changed the code tohttp.Server.ListenAndServeTLS
, the server ran on http2.I expected the server to run on http2 with
http.Sever.Serve
.The server ran on http1/1
The text was updated successfully, but these errors were encountered: