I'm trying to set up a TCP server which accepts and decodes HTTP/2 data. The code to actually parse the frames can be found in this article:
Decoding http2 frame header/data in Go
I'm having issues, however, with setting up the server. The connection gets accepted, but it hangs on framer.ReadFrame()
. Here is a code example:
// generate with: openssl req -x509 -newkey rsa:4096 -keyout server.key -out server.pem -days 365 -nodes
cert, err := tls.LoadX509KeyPair("server.pem", "server.key")
if err != nil {
log.Fatal(err)
}
tlsCfg := &tls.Config{
Certificates: []tls.Certificate{cert},
NextProtos: []string{"h2"},
}
l, err := tls.Listen("tcp", ":8787", tlsCfg)
if err != nil {
log.Fatal(err)
}
defer l.Close()
conn, err := l.Accept()
if err != nil {
log.Fatalln(err)
}
defer conn.Close()
framer := http2.NewFramer(conn, conn)
frame, _ := framer.ReadFrame() // Here it hangs
I request the server using curl
curl -v https://127.0.0.1:8787/ -k --http2