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:
parent
2c58cb36f9
commit
4187e1f49f
25
src/net/http/httptrace/example_test.go
Normal file
25
src/net/http/httptrace/example_test.go
Normal 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)
|
||||
}
|
@ -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.
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user