Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gptankit opened this issue May 21, 2018 · 5 comments

Comments

Projects
None yet
4 participants
@gptankit
Copy link

commented May 21, 2018

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?

@ALTree

This comment has been minimized.

Copy link
Member

commented May 21, 2018

Hi,

the Go project does not use its bug tracker for general discussion or asking questions. The Github bug tracker is only used for tracking bugs and proposals going through the Proposal Process.

Please see the Questions wiki page; it has a list of good places for asking questions. Thanks!

Closing, since it appears that this is not a bug. If it turns out to be a bug, comment here and we'll re-open.

@ALTree ALTree closed this May 21, 2018

@gptankit

This comment has been minimized.

Copy link
Author

commented May 21, 2018

I won't categorize it as a bug, but it certainly seems like it's a feature or documentation miss. There might be allternatives to what I am trying to do but it certainly is not clear.

@ALTree

This comment has been minimized.

Copy link
Member

commented May 21, 2018

Okay.. re-opening and marking as a possible doc enhancement.

@ALTree ALTree reopened this May 21, 2018

@ALTree ALTree changed the title http.ReadRequest doesn't recognize http2? net/http: ReadRequest doesn't recognize http2? May 21, 2018

@bcmills

This comment has been minimized.

Copy link
Member

commented May 21, 2018

CC: @bradfitz

@gopherbot

This comment has been minimized.

Copy link

commented May 21, 2018

Change https://golang.org/cl/113817 mentions this issue: net/http: clarify that ReadRequest is only for HTTP/1.x

@gopherbot gopherbot closed this in d583ca7 May 21, 2018

@golang golang locked and limited conversation to collaborators May 21, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.