1
0
mirror of https://github.com/golang/go synced 2024-11-23 15:40:06 -07:00

net/http/httptrace: add simple example and fix copyright header

Partially addresses #16360

Change-Id: I67a328302d7d91231f348d934e4232fcb844830a
Reviewed-on: https://go-review.googlesource.com/27398
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Billy Lynch 2016-08-19 01:40:08 -04:00 committed by Brad Fitzpatrick
parent 2c58cb36f9
commit 4187e1f49f
3 changed files with 27 additions and 2 deletions

View File

@ -0,0 +1,25 @@
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package httptrace_test
import (
"fmt"
"net/http"
"net/http/httptrace"
)
func ExampleTrace() {
req, _ := http.NewRequest("GET", "http://example.com", nil)
trace := &httptrace.ClientTrace{
GotConn: func(connInfo httptrace.GotConnInfo) {
fmt.Printf("Got Conn: %+v\n", connInfo)
},
DNSDone: func(dnsInfo httptrace.DNSDoneInfo) {
fmt.Printf("DNS Info: %+v\n", dnsInfo)
},
}
req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace))
http.DefaultClient.Do(req)
}

View File

@ -1,6 +1,6 @@
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.h
// license that can be found in the LICENSE file.
// Package httptrace provides mechanisms to trace the events within
// HTTP client requests.

View File

@ -1,6 +1,6 @@
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.h
// license that can be found in the LICENSE file.
package httptrace