Hello gophers,
I am trying to read http2 request on a tcp connection, which is set up like this -
cert, err := tls.LoadX509KeyPair(certfile, certkeyfile)
if err != nil {
return nil, err
}
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{cert},
ServerName: "mysrvr",
NextProtos: []string{"h2", "http/1.1", "http/1.0"},
Time: time.Now,
Rand: rand.Reader,
}
tlsConfig.BuildNameToCertificate()
tlsConfig.PreferServerCipherSuites = true
listener := tls.Listen("tcp", ":"+sqp.ListenerPort, tlsConfig)
for {
conn, err := listener.Accept()
reader := bufio.NewReader(conn)
req, err := http.ReadRequest(reader) // problem here
// do other things with req
}
When I do **curl
https://127.0.0.1:8000 -k --http2** to the above server, I was expecting http.ReadRequest to parse the request same as it does for http/1.1 or 1.0.
What I saw was that the request contained PRI method (which is defined in http2 rfc) and even if I ignore the complete connection preface and the SETTINGS frame after it, I still don't get the original request. Though if I try reading directly from tcp connection, I get a blob right after PRI and SETTINGS frame.