1
2
3
4
5 package httptrace_test
6
7 import (
8 "fmt"
9 "log"
10 "net/http"
11 "net/http/httptrace"
12 )
13
14 func Example() {
15 req, _ := http.NewRequest("GET", "http://example.com", nil)
16 trace := &httptrace.ClientTrace{
17 GotConn: func(connInfo httptrace.GotConnInfo) {
18 fmt.Printf("Got Conn: %+v\n", connInfo)
19 },
20 DNSDone: func(dnsInfo httptrace.DNSDoneInfo) {
21 fmt.Printf("DNS Info: %+v\n", dnsInfo)
22 },
23 }
24 req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace))
25 _, err := http.DefaultTransport.RoundTrip(req)
26 if err != nil {
27 log.Fatal(err)
28 }
29 }
30
View as plain text