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

Closed
rakheshkumbi opened this issue Sep 17, 2020 · 6 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@rakheshkumbi
Copy link

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

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

cc @fraenkel

@fraenkel
Copy link
Contributor

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

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

@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 22, 2020
@seankhliao
Copy link
Member

closing as dup of #38064

@linchuan4028
Copy link

any update on this issue? I believe that I encounter the same problem.

@golang golang locked and limited conversation to collaborators May 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

7 participants