Fetch the repository succeeded.
package colly
import (
"net/http"
"net/http/httptrace"
"time"
)
// HTTPTrace provides a datastructure for storing an http trace.
type HTTPTrace struct {
start, connect time.Time
ConnectDuration time.Duration
FirstByteDuration time.Duration
}
// trace returns a httptrace.ClientTrace object to be used with an http
// request via httptrace.WithClientTrace() that fills in the HttpTrace.
func (ht *HTTPTrace) trace() *httptrace.ClientTrace {
trace := &httptrace.ClientTrace{
ConnectStart: func(network, addr string) { ht.connect = time.Now() },
ConnectDone: func(network, addr string, err error) {
ht.ConnectDuration = time.Since(ht.connect)
},
GetConn: func(hostPort string) { ht.start = time.Now() },
GotFirstResponseByte: func() {
ht.FirstByteDuration = time.Since(ht.start)
},
}
return trace
}
// WithTrace returns the given HTTP Request with this HTTPTrace added to its
// context.
func (ht *HTTPTrace) WithTrace(req *http.Request) *http.Request {
return req.WithContext(httptrace.WithClientTrace(req.Context(), ht.trace()))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。