-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathclient_tracer.go
81 lines (69 loc) · 1.89 KB
/
client_tracer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package harlog
import (
"crypto/tls"
"net/http/httptrace"
"time"
)
func newClientTracer() (*clientTracer, *httptrace.ClientTrace, func()) {
ct1 := &clientTracer{
startAt: time.Now(),
}
ct2 := &httptrace.ClientTrace{
GetConn: ct1.GetConn,
GotConn: ct1.GotConn,
PutIdleConn: nil,
GotFirstResponseByte: ct1.GotFirstResponseByte,
Got100Continue: nil,
Got1xxResponse: nil,
DNSStart: ct1.DNSStart,
DNSDone: ct1.DNSDone,
ConnectStart: nil,
ConnectDone: nil,
TLSHandshakeStart: ct1.TLSHandshakeStart,
TLSHandshakeDone: ct1.TLSHandshakeDone,
WroteHeaderField: nil,
WroteHeaders: nil,
Wait100Continue: nil,
WroteRequest: ct1.WroteRequest,
}
finish := func() {
ct1.endAt = time.Now()
}
return ct1, ct2, finish
}
type clientTracer struct {
startAt time.Time
connStart time.Time
connObtained time.Time
firstResponseByte time.Time
dnsStart time.Time
dnsEnd time.Time
tlsHandshakeStart time.Time
tlsHandshakeEnd time.Time
writeRequest time.Time
endAt time.Time
}
func (ct *clientTracer) GetConn(hostPort string) {
ct.connStart = time.Now()
}
func (ct *clientTracer) GotConn(info httptrace.GotConnInfo) {
ct.connObtained = time.Now()
}
func (ct *clientTracer) GotFirstResponseByte() {
ct.firstResponseByte = time.Now()
}
func (ct *clientTracer) DNSStart(info httptrace.DNSStartInfo) {
ct.dnsStart = time.Now()
}
func (ct *clientTracer) DNSDone(info httptrace.DNSDoneInfo) {
ct.dnsEnd = time.Now()
}
func (ct *clientTracer) TLSHandshakeStart() {
ct.tlsHandshakeStart = time.Now()
}
func (ct *clientTracer) TLSHandshakeDone(tls.ConnectionState, error) {
ct.tlsHandshakeEnd = time.Now()
}
func (ct *clientTracer) WroteRequest(info httptrace.WroteRequestInfo) {
ct.writeRequest = time.Now()
}