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: Protocol upgrade from HTTP1.1 to h2c(HTTP2) when the request contains payload body, is failing. #41445

Open
rakheshkumbi opened this issue Sep 17, 2020 · 4 comments

Comments

@rakheshkumbi
Copy link

@rakheshkumbi rakheshkumbi commented Sep 17, 2020

When client sends request to upgrade from http1.1 to http2 and the request contains the payload body, the server fails to upgrade to http2. (RFC 7540 section 3.2)
And observed the following error.
2020/09/17 12:11:10 http: response.Write on hijacked connection from fmt.Fprintf (print.go:205)

GO Versions
go version go1.15.2 linux/amd64

Steps to Reproduce

  1. Run the server.
  2. Capture the packets using wireshark
  3. send upgrade request from curl and include payload body
    sudo curl -vs -o /dev/null --http2 --request GET --data '{"username":"xyz","password":"xyz"}' http://localhost:8090/hello

Expected behavior:
The HTTP2 upgrade should be successful and the server should send the response back to the client.

Code Snippets

package main

import (
        "fmt"
        "net"
        "net/http"
        "os"

        "golang.org/x/net/http2"
        "golang.org/x/net/http2/h2c"
)


func main() {
        H2CUpgrade()
}

func H2CUpgrade() {
        h2s := &http2.Server{}

        handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
                fmt.Fprintf(w, "Hello, %v, http: %v", r.URL.Path, r.TLS == nil)
                return

        })

        server := &http.Server{
                Addr:    "0.0.0.0:8090",
                Handler: h2c.NewHandler(handler, h2s),
        }

        fmt.Printf("Listening [0.0.0.0:8090]...\n")
        server.ListenAndServe()
}
@gopherbot gopherbot added this to the Unreleased milestone Sep 17, 2020
@rakheshkumbi
Copy link
Author

@rakheshkumbi rakheshkumbi commented Sep 17, 2020

Network trace:

image

@rakheshkumbi rakheshkumbi changed the title x/net/http: Protocol upgrade from HTTP1.1 to h2c(HTTP2) is failing with error - response.Write on hijacked connection x/net/http: Protocol upgrade from HTTP1.1 to h2c(HTTP2) when the request contains payload body, is failing. Sep 17, 2020
@rakheshkumbi rakheshkumbi changed the title x/net/http: Protocol upgrade from HTTP1.1 to h2c(HTTP2) when the request contains payload body, is failing. net/http: Protocol upgrade from HTTP1.1 to h2c(HTTP2) when the request contains payload body, is failing. Sep 17, 2020
@networkimprov
Copy link

@networkimprov networkimprov commented Sep 17, 2020

@fraenkel
Copy link
Contributor

@fraenkel fraenkel commented Sep 17, 2020

Its broken, but so is h2c. If you attempt to do a POST instead of GET which is more common with data, you get the same error.
There are no tests for h2c, so I am more concerned that there is more than just this example that is broken.

@rakheshkumbi
Copy link
Author

@rakheshkumbi rakheshkumbi commented Sep 17, 2020

Thank you for the update @fraenkel. Do we have any solution or workaround for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.