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/httputil: support for HTTP/2 in ReverseProxy #16696

Closed
jmhodges opened this issue Aug 15, 2016 · 5 comments
Closed

net/http/httputil: support for HTTP/2 in ReverseProxy #16696

jmhodges opened this issue Aug 15, 2016 · 5 comments
Milestone

Comments

@jmhodges
Copy link
Contributor

Currently, httputil.ReverseProxy hardcodes the HTTP/1.1 protocol in requests going to the backend service. It would be nice if it could support HTTP/2.

That hardcoding seems to have been around since the beginning of reverseproxy.go's existence, so I'm not sure if there are real constraints such that ReverseProxy can't be allowed to use the usual net/http HTTP protocol version detection or if this was just some dregs.

@bradfitz
Copy link
Contributor

No reason I recall. I think it was just muscle memory when I wrote it.

@jmhodges
Copy link
Contributor Author

jmhodges commented Aug 15, 2016

I started digging into this, and can't seem to write a test that has an HTTP/2 enabled client.

The problem is that HTTP/2 is disabled on all clients that set InsecureSkipVerify on their transports, which is needed to use httptest's HTTPS servers, because TLSClientConfig will be non-nil but there's no public func like http2.ConfigureTransport to reenable it. The one bundled in the net/http library is unexported and so are the structs it relies on.

So, I can't seem to figure out how to get a HTTP/2 enabled client inside a test in net/http/httputil.

But maybe there's something I missed?

@jmhodges
Copy link
Contributor Author

(edited last comment to be more clear)

@rakyll rakyll added this to the Go1.8 milestone Aug 15, 2016
@bradfitz
Copy link
Contributor

bradfitz commented Sep 2, 2016

Actually, the hard-coding of the fields is pointless.

From the docs:

https://golang.org/pkg/net/http/#Request

        // The protocol version for incoming server requests.
        //
        // For client requests these fields are ignored. The HTTP
        // client code always uses either HTTP/1.1 or HTTP/2.
        // See the docs on Transport for details.
        Proto      string // "HTTP/1.0"
        ProtoMajor int    // 1
        ProtoMinor int    // 0

And I saw another bug where people were using ReverseProxy with HTTP/2 just fine. (But that wasn't the point of the bug, IIRC).

So I think there's nothing to do here.

I'll remove those lines from the ReverseProxy code, though.

@bradfitz bradfitz closed this as completed Sep 2, 2016
@gopherbot
Copy link

CL https://golang.org/cl/28412 mentions this issue.

gopherbot pushed a commit that referenced this issue Sep 2, 2016
…ible

The http.Transport's retry can't retry requests with non-nil
bodies. When cloning an incoming server request into an outgoing
client request, nil out the Body field if the ContentLength is 0. (For
server requests, Body is always non-nil, even for GET, HEAD, etc.)

Also, don't use the deprecated CancelRequest and use Context instead.

And don't set Proto, ProtoMajor, ProtoMinor. Those are ignored in
client requests, which was probably a later documentation
clarification.

Fixes #16036
Updates #16696 (remove useless Proto lines)

Change-Id: I70a869e9bd4bf240c5838e82fb5aa695a539b343
Reviewed-on: https://go-review.googlesource.com/28412
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
@golang golang locked and limited conversation to collaborators Sep 2, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants