Skip to content

Commit c6f04bf

Browse files
authored
Merge pull request #9 from jabley/feature/tls-handshakes
feat: support tracing TLS handshake times
2 parents 4b991a7 + e5777ac commit c6f04bf

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"crypto/tls"
45
"encoding/json"
56
"fmt"
67
"io"
@@ -115,6 +116,8 @@ type TimingContext struct {
115116
ConnectStart float64 `json:"connectStart"`
116117
ConnectDone float64 `json:"connectDone"`
117118
WroteRequest float64 `json:"wroteRequest"`
119+
TLSHandshakeStart float64 `json:"tlsHandshakeStart"`
120+
TLSHandshakeDone float64 `json:"tlsHandshakeDone"`
118121
Total float64 `json:"total"`
119122
}
120123

@@ -202,6 +205,12 @@ func doIt(URL string) (*TimingContext, error) {
202205
ConnectStart: func(network, addr string) { timingContext.ConnectStart = timingContext.Elapsed() },
203206
ConnectDone: func(network, addr string, err error) { timingContext.ConnectDone = timingContext.Elapsed() },
204207
WroteRequest: func(e httptrace.WroteRequestInfo) { timingContext.WroteRequest = timingContext.Elapsed() },
208+
TLSHandshakeStart: func() { timingContext.TLSHandshakeStart = timingContext.Elapsed() },
209+
TLSHandshakeDone: func(_cs tls.ConnectionState, err error) {
210+
if err == nil {
211+
timingContext.TLSHandshakeDone = timingContext.Elapsed()
212+
}
213+
},
205214
}))
206215

207216
res, err := client.Do(req)

0 commit comments

Comments
 (0)