-
Notifications
You must be signed in to change notification settings - Fork 0
/
messing
51 lines (43 loc) · 1.35 KB
/
messing
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
package main
import (
"crypto/tls"
"fmt"
"log"
"net/http"
"net/http/httptrace"
"time"
)
func actual(url string) {
req, _ := http.NewRequest("GET", url, nil)
var start, connect, dns, tlsHandshake time.Time
var test, connc float32
trace := &httptrace.ClientTrace{
DNSStart: func(dsi httptrace.DNSStartInfo) { dns = time.Now() },
DNSDone: func(ddi httptrace.DNSDoneInfo) {
fmt.Printf("DNS Done: %v\n", time.Since(dns))
test = float32(float32(test) / float32(time.Millisecond))
},
TLSHandshakeStart: func() { tlsHandshake = time.Now() },
TLSHandshakeDone: func(cs tls.ConnectionState, err error) {
fmt.Printf("TLS Handshake: %v\n", time.Since(tlsHandshake))
},
ConnectStart: func(network, addr string) { connect = time.Now() },
ConnectDone: func(network, addr string, err error) {
fmt.Printf("Connect time: %v\n", time.Since(connect))
connc = float32(float32(time.Since(connect)) / float32(time.Millisecond))
},
GotFirstResponseByte: func() {
fmt.Printf("Time from start to first byte: %v\n", time.Since(start))
},
}
fmt.Printf("DNS Done2: %v\n", connc)
req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace))
start = time.Now()
if _, err := http.DefaultTransport.RoundTrip(req); err != nil {
log.Fatal(err)
}
fmt.Printf("Total time: %v\n", time.Since(start))
}
func main() {
actual("http://google.com")
}