2018-08-23 08:11
浏览 132

Golang TCP服务器读取HTTP / 2帧

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 {

tlsCfg := &tls.Config{
    Certificates: []tls.Certificate{cert},
    NextProtos:   []string{"h2"},

l, err := tls.Listen("tcp", ":8787", tlsCfg)
if err != nil {
defer l.Close()

conn, err := l.Accept()
if err != nil {
defer conn.Close()

framer := http2.NewFramer(conn, conn)
frame, _ := framer.ReadFrame() // Here it hangs

I request the server using curl

curl -v -k --http2
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题