Skip to content

Commit

Permalink
net/http: update bundled x/net/http2 for httptrace changes
Browse files Browse the repository at this point in the history
Updates x/net/http2 to 3b99394 for golang.org/cl/23205

And associated tests.

Fixes #12580

Change-Id: I1f4b59267b453d241f2afaa315b7fe10d477e52d
Reviewed-on: https://go-review.googlesource.com/23206
Reviewed-by: Andrew Gerrand <[email protected]>
Run-TryBot: Brad Fitzpatrick <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
  • Loading branch information
bradfitz committed May 18, 2016
1 parent 4d2ac54 commit 1119af8
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 17 deletions.
7 changes: 7 additions & 0 deletions src/net/http/clientserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ func (t *clientServerTest) close() {
t.ts.Close()
}

func (t *clientServerTest) scheme() string {
if t.h2 {
return "https"
}
return "http"
}

const (
h1Mode = false
h2Mode = true
Expand Down
58 changes: 58 additions & 0 deletions src/net/http/h2_bundle.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/net/http/httptrace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type ClientTrace struct {
// connection reuse is disabled via Transport.DisableKeepAlives.
// PutIdleConn is called before the caller's Response.Body.Close
// call returns.
// For HTTP/2, this hook is not currently used.
PutIdleConn func(err error)

// GotFirstResponseByte is called when the first byte of the response
Expand Down
38 changes: 21 additions & 17 deletions src/net/http/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3193,26 +3193,26 @@ func TestTransportResponseHeaderLength(t *testing.T) {
}
}

func TestTransportEventTrace(t *testing.T) { testTransportEventTrace(t, false) }
func TestTransportEventTrace(t *testing.T) { testTransportEventTrace(t, h1Mode, false) }
func TestTransportEventTrace_h2(t *testing.T) { testTransportEventTrace(t, h2Mode, false) }

// test a non-nil httptrace.ClientTrace but with all hooks set to zero.
func TestTransportEventTrace_NoHooks(t *testing.T) { testTransportEventTrace(t, true) }
func TestTransportEventTrace_NoHooks(t *testing.T) { testTransportEventTrace(t, h1Mode, true) }
func TestTransportEventTrace_NoHooks_h2(t *testing.T) { testTransportEventTrace(t, h2Mode, true) }

func testTransportEventTrace(t *testing.T, noHooks bool) {
func testTransportEventTrace(t *testing.T, h2 bool, noHooks bool) {
defer afterTest(t)
const resBody = "some body"
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
cst := newClientServerTest(t, h2, HandlerFunc(func(w ResponseWriter, r *Request) {
if _, err := ioutil.ReadAll(r.Body); err != nil {
t.Error(err)
}
io.WriteString(w, resBody)
}))
defer ts.Close()
tr := &Transport{
ExpectContinueTimeout: 1 * time.Second,
defer cst.close()
if !h2 {
cst.tr.ExpectContinueTimeout = 1 * time.Second
}
defer tr.CloseIdleConnections()
c := &Client{Transport: tr}

var mu sync.Mutex
var buf bytes.Buffer
Expand All @@ -3223,7 +3223,8 @@ func testTransportEventTrace(t *testing.T, noHooks bool) {
buf.WriteByte('\n')
}

ip, port, err := net.SplitHostPort(ts.Listener.Addr().String())
addrStr := cst.ts.Listener.Addr().String()
ip, port, err := net.SplitHostPort(addrStr)
if err != nil {
t.Fatal(err)
}
Expand All @@ -3237,7 +3238,7 @@ func testTransportEventTrace(t *testing.T, noHooks bool) {
return []net.IPAddr{{IP: net.ParseIP(ip)}}, nil
})

req, _ := NewRequest("POST", "http://dns-is-faked.golang:"+port, strings.NewReader("some body"))
req, _ := NewRequest("POST", cst.scheme()+"://dns-is-faked.golang:"+port, strings.NewReader("some body"))
trace := &httptrace.ClientTrace{
GetConn: func(hostPort string) { logf("Getting conn for %v ...", hostPort) },
GotConn: func(ci httptrace.GotConnInfo) { logf("got conn: %+v", ci) },
Expand All @@ -3263,7 +3264,7 @@ func testTransportEventTrace(t *testing.T, noHooks bool) {
req = req.WithContext(httptrace.WithClientTrace(ctx, trace))

req.Header.Set("Expect", "100-continue")
res, err := c.Do(req)
res, err := cst.c.Do(req)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -3292,14 +3293,17 @@ func testTransportEventTrace(t *testing.T, noHooks bool) {
wantSub("Getting conn for dns-is-faked.golang:" + port)
wantSub("DNS start: {Host:dns-is-faked.golang}")
wantSub("DNS done: {Addrs:[{IP:" + ip + " Zone:}] Err:<nil> Coalesced:false}")
wantSub("Connecting to tcp " + ts.Listener.Addr().String())
wantSub("connected to tcp " + ts.Listener.Addr().String() + " = <nil>")
wantSub("Connecting to tcp " + addrStr)
wantSub("connected to tcp " + addrStr + " = <nil>")
wantSub("Reused:false WasIdle:false IdleTime:0s")
wantSub("first response byte")
wantSub("PutIdleConn = <nil>")
if !h2 {
wantSub("PutIdleConn = <nil>")
// TODO: implement these next two for Issue 13851
wantSub("Wait100Continue")
wantSub("Got100Continue")
}
wantSub("WroteRequest: {Err:<nil>}")
wantSub("Wait100Continue")
wantSub("Got100Continue")
if strings.Contains(got, " to udp ") {
t.Errorf("should not see UDP (DNS) connections")
}
Expand Down

0 comments on commit 1119af8

Please sign in to comment.