Skip to content

net/http: ReadRequest doesn't recognize http2? #25476

Closed
@gptankit

Description

@gptankit

What version of Go are you using (go version)?

Go 1.10.2

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

linux/amd64

What did you do?

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
             }

What did you expect to see?

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 did you see instead?

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.

I looked at ParseHTTPVersion (https://golang.org/src/net/http/request.go?s=29537:29588#L708) called from readRequest and it doesn't even have a case for HTTP/2. Does it mean I can't use http.ReadRequest for HTTP/2 requests?

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions