golang/go

net/http: make Transport return a net.Conn Response.Body on successful CONNECT

Open

#32,273 opened on May 28, 2019

View on GitHub
 (8 comments) (0 reactions) (0 assignees)Go (19,008 forks)batch import
NeedsFixhelp wanted

Repository metrics

Stars
 (133,883 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

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

Does this issue reproduce with the latest release?

Yes

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

What did you do?

		req := &http.Request{
			Method: "CONNECT",
			URL: &url.URL{
				Scheme: "https",
				Host:   proxyHost,
				Opaque: addr,
			},
		}
		req.Host = proxyHost
		res, err := http.DefaultClient.Do(req)
		if err != nil {
			return errors.Annotate(err, "error connecting to https proxy")
		}
		if res.StatusCode < 200 || res.StatusCode > 299 {
			panic(fmt.Sprintf("error connecting to https proxy, status: %d", res.StatusCode))
		}
		conn, ok := res.Body.(net.Conn)
		if ok != true {
			return errors.New(fmt.Sprintf("res.Body is not a net.Conn, it has type %s", reflect.TypeOf(res.Body)))
		}
		_ = tls.Client(conn, tlsConfig)

What did you expect to see?

As per #17227, res.Body should be a net.Conn after successful CONNECT.

What did you see instead?

Instead it is of the type *http.bodyEOFSignal

@bradfitz can you please take a look?

Contributor guide