Commit fbd690d9 authored by ayanamist's avatar ayanamist Committed by Brad Fitzpatrick

x/net/http2: use request url scheme

The existing implementation has a hardcoded "https" scheme for
all request, since it allows http scheme in the request, it should
use the scheme in the request url.

Fixes golang/go#17257

Change-Id: Ibd9528df0328d7630ee94a006db694645625cdc9
Reviewed-on: https://go-review.googlesource.com/29975
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 9f0e377a
...@@ -1046,7 +1046,7 @@ func (cc *ClientConn) encodeHeaders(req *http.Request, addGzipHeader bool, trail ...@@ -1046,7 +1046,7 @@ func (cc *ClientConn) encodeHeaders(req *http.Request, addGzipHeader bool, trail
cc.writeHeader(":method", req.Method) cc.writeHeader(":method", req.Method)
if req.Method != "CONNECT" { if req.Method != "CONNECT" {
cc.writeHeader(":path", path) cc.writeHeader(":path", path)
cc.writeHeader(":scheme", "https") cc.writeHeader(":scheme", req.URL.Scheme)
} }
if trailers != "" { if trailers != "" {
cc.writeHeader("trailer", trailers) cc.writeHeader("trailer", trailers)
......
...@@ -52,6 +52,16 @@ func TestTransportExternal(t *testing.T) { ...@@ -52,6 +52,16 @@ func TestTransportExternal(t *testing.T) {
res.Write(os.Stdout) res.Write(os.Stdout)
} }
type fakeTLSConn struct {
net.Conn
}
func (c *fakeTLSConn) ConnectionState() tls.ConnectionState {
return tls.ConnectionState{
Version: tls.VersionTLS12,
}
}
func startH2cServer(t *testing.T) net.Listener { func startH2cServer(t *testing.T) net.Listener {
h2Server := &Server{} h2Server := &Server{}
l := newLocalListener(t) l := newLocalListener(t)
...@@ -61,8 +71,8 @@ func startH2cServer(t *testing.T) net.Listener { ...@@ -61,8 +71,8 @@ func startH2cServer(t *testing.T) net.Listener {
t.Error(err) t.Error(err)
return return
} }
h2Server.ServeConn(conn, &ServeConnOpts{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { h2Server.ServeConn(&fakeTLSConn{conn}, &ServeConnOpts{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %v", r.URL.Path) fmt.Fprintf(w, "Hello, %v, http: %v", r.URL.Path, r.TLS == nil)
})}) })})
}() }()
return l return l
...@@ -92,7 +102,7 @@ func TestTransportH2c(t *testing.T) { ...@@ -92,7 +102,7 @@ func TestTransportH2c(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if got, want := string(body), "Hello, /foobar"; got != want { if got, want := string(body), "Hello, /foobar, http: true"; got != want {
t.Fatalf("response got %v, want %v", got, want) t.Fatalf("response got %v, want %v", got, want)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment