visit visits a url and times the interaction. If the response is a 30x, visit follows the redirect.
(url *url.URL)
| 216 | // visit visits a url and times the interaction. |
| 217 | // If the response is a 30x, visit follows the redirect. |
| 218 | func visit(url *url.URL) { |
| 219 | req := newRequest(httpMethod, url, postBody) |
| 220 | |
| 221 | var t0, t1, t2, t3, t4, t5, t6 time.Time |
| 222 | |
| 223 | trace := &httptrace.ClientTrace{ |
| 224 | DNSStart: func(_ httptrace.DNSStartInfo) { t0 = time.Now() }, |
| 225 | DNSDone: func(_ httptrace.DNSDoneInfo) { t1 = time.Now() }, |
| 226 | ConnectStart: func(_, _ string) { |
| 227 | if t1.IsZero() { |
| 228 | // connecting to IP |
| 229 | t1 = time.Now() |
| 230 | } |
| 231 | }, |
| 232 | ConnectDone: func(net, addr string, err error) { |
| 233 | if err != nil { |
| 234 | log.Fatalf("unable to connect to host %v: %v", addr, err) |
| 235 | } |
| 236 | t2 = time.Now() |
| 237 | |
| 238 | printf("\n%s%s\n", color.GreenString("Connected to "), color.CyanString(addr)) |
| 239 | }, |
| 240 | GotConn: func(_ httptrace.GotConnInfo) { t3 = time.Now() }, |
| 241 | GotFirstResponseByte: func() { t4 = time.Now() }, |
| 242 | TLSHandshakeStart: func() { t5 = time.Now() }, |
| 243 | TLSHandshakeDone: func(_ tls.ConnectionState, _ error) { t6 = time.Now() }, |
| 244 | } |
| 245 | req = req.WithContext(httptrace.WithClientTrace(context.Background(), trace)) |
| 246 | |
| 247 | tr := &http.Transport{ |
| 248 | Proxy: http.ProxyFromEnvironment, |
| 249 | MaxIdleConns: 100, |
| 250 | IdleConnTimeout: 90 * time.Second, |
| 251 | TLSHandshakeTimeout: 10 * time.Second, |
| 252 | ExpectContinueTimeout: 1 * time.Second, |
| 253 | ForceAttemptHTTP2: true, |
| 254 | } |
| 255 | |
| 256 | switch { |
| 257 | case fourOnly: |
| 258 | tr.DialContext = dialContext("tcp4") |
| 259 | case sixOnly: |
| 260 | tr.DialContext = dialContext("tcp6") |
| 261 | } |
| 262 | |
| 263 | switch url.Scheme { |
| 264 | case "https": |
| 265 | host, _, err := net.SplitHostPort(req.Host) |
| 266 | if err != nil { |
| 267 | host = req.Host |
| 268 | } |
| 269 | |
| 270 | tr.TLSClientConfig = &tls.Config{ |
| 271 | ServerName: host, |
| 272 | InsecureSkipVerify: insecure, |
| 273 | Certificates: readClientCert(clientCertFile), |
| 274 | MinVersion: tls.VersionTLS12, |
| 275 | } |
no test coverage detected