I posted here mainly because there is no "ServeTLS" for http2.Server in x/net/http2. So unless I'm mistaken, we can't really use directly and simply http2.Server.
The only entry point to using http2.Server is ServeConn which must be called from a TLSNextProto function of a http.Server (which makes sense).
http2.ConfigureServer can be used for that but it also adds "http/1.1" after "h2" ( why ?! )
Then calling ServeTLS also add "http/1.1" if not found (?!).
So the only workaround I found is by duplicating the code of ServeTLS:
- call http2.ConfigureServer (which add "h2" but also "http/1.1" ?! to ALPN)
- remove "http1.1" from TLSConfig.NextProtos
- set up the TLS listener
- call Serve on that TLS listener
This seems to work but doesn't fully replicate the net/http ServeTLS function. We also need to set http2.Server.NewWriteScheduler as it is set in net/http/Server.setupHTTP2_ServeTLS.
This isn't very future proof as any bug fixes/changes to net/http/Server.ServeTLS need to be backported but I understand this was done mainly to add HTTP/2 to the existing net/http 1.1 server rather then be a "HTTP/2 standalone server" implementation.