Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPRoundTripDurations ¶
type HTTPRoundTripDurations struct { // duration of round-trip parts Resolve time.Duration Connect time.Duration TLS time.Duration // since FirstResponseByte Headers time.Duration // since ReadHeaders Body time.Duration // since start of request, for ease FirstResponseByte time.Duration Total time.Duration }
type HTTPRoundTripTimings ¶
type HTTPRoundTripTimings struct { RequestStart time.Time DNSStart time.Time DNSDone time.Time ConnectStart time.Time ConnectDone time.Time TLSStart time.Time TLSDone time.Time GotFirstResponseByte time.Time ReadHeaders time.Time ReadBody time.Time RequestDone time.Time }
Absolute timings since start of request
func GetRoundTripTimings ¶
func GetRoundTripTimings(c *http.Client, req *http.Request, readBody bool) (HTTPRoundTripTimings, *http.Response, []byte, error)
Example ¶
req, _ := http.NewRequest("GET", "https://ipv4.google.com", nil) // It's the only way to set global deadline, including all redirects, upgrades, etc deadline := 500 * time.Millisecond ctx, cancel := context.WithCancel(context.Background()) _ = time.AfterFunc(deadline, func() { cancel() }) req = req.WithContext(ctx) client := &http.Client{Transport: http.DefaultTransport} // Granular timeouts example // Total request timeout will not be limited by them, use WithCancel context instead! /*&http.Client{ Transport: &http.Transport{ DialContext: (&net.Dialer{ Timeout: 150 * time.Millisecond, }).DialContext, TLSHandshakeTimeout: 300 * time.Millisecond, IdleConnTimeout: 300 * time.Millisecond, ResponseHeaderTimeout: 300 * time.Millisecond, ExpectContinueTimeout: 300 * time.Millisecond, ForceAttemptHTTP2: true, }, Timeout: 300 * time.Millisecond, }*/ ht, _, _, err := GetRoundTripTimings(client, req, false) if err != nil { log.Printf("ExampleGetRoundTripTimings [durations=%+v; timings=%+v] error: %s", ht.Durations(), ht, err) return } log.Printf("ExampleGetRoundTripTimings [durations=%+v; timings=%+v] ok", ht.Durations(), ht)
Output:
func (HTTPRoundTripTimings) Durations ¶
func (ht HTTPRoundTripTimings) Durations() HTTPRoundTripDurations
Click to show internal directories.
Click to hide internal directories.