I figured it out. ServeConn expects Handshake to have been called on the
tls.Conn.

It is unclear to me what an appropriate fix would be. Maybe just update the
documentation for http2.(*Server).ServeConn?

On Tue, Aug 11, 2020 at 11:06 AM Ian Gudger <i...@iangudger.com> wrote:

> I am trying to use the http2.Server directly. I can't use the standard
> library http.Server because it has a hard dependency on receiving a
> *tls.Conn for http2 and I would like to use a wrapper. For now though, I am
> trying to get http2.Server working with the bare tls types. I am using what
> seems like the simplest way to use it, but it doesn't work and I am having
> trouble figuring out why. It seems that my handler is never executed and my
> browser returns ERR_CONNECTION_CLOSED.
>
> Usage that doesn't work:
>
>> l, err := net.Listen("tcp", ":8443")
>> if err != nil {
>>     panic(err)
>> }
>> l = tls.NewListener(l, &tls.Config{NextProtos:
>> []string{http2.NextProtoTLS}, Certificates: []tls.Certificate{rootTLSCert}})
>> var srv http2.Server
>> opts := http2.ServeConnOpts{Handler: http.HandlerFunc(func(w
>> http.ResponseWriter, r *http.Request) {
>>     w.Write([]byte("hello world"))
>> })}
>> for {
>>     c, err := l.Accept()
>>     // TODO: Handle temporary errors.
>>     if err != nil {
>>         panic(err)
>>     }
>>     go srv.ServeConn(c, &opts)
>> }
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CANFXSj0jR9E%3Dio4b0dygynOFGj_wobMB0T2HQcdOtJx4ftTmew%40mail.gmail.com.

Reply via email to