gitee.com/quant1x/gox@v1.21.2/http/client.go (about) 1 package http 2 3 import ( 4 "math" 5 "net" 6 "net/http" 7 "time" 8 ) 9 10 const ( 11 // DefaultRedirects is the default number of times an Attacker follows 12 // redirects. 13 DefaultRedirects = 10 14 // DefaultTimeout is the default amount of time an Attacker waits for a request 15 // before it times out. 16 DefaultTimeout = 30 * time.Second 17 // DefaultConnections is the default amount of max open idle connections per 18 // target host. 19 DefaultConnections = 10000 20 // DefaultMaxConnections is the default amount of connections per target 21 // host. 22 DefaultMaxConnections = 0 23 // DefaultWorkers is the default initial number of workers used to carry an attack. 24 DefaultWorkers = 10 25 // DefaultMaxWorkers is the default maximum number of workers used to carry an attack. 26 DefaultMaxWorkers = math.MaxUint64 27 // DefaultMaxBody is the default max number of bytes to be read from response bodies. 28 // Defaults to no limit. 29 DefaultMaxBody = int64(-1) 30 // NoFollow is the value when redirects are not followed but marked successful 31 NoFollow = -1 32 ) 33 34 // DefaultRoundTripper is used if no RoundTripper is set in Config. 35 var DefaultRoundTripper http.RoundTripper = &http.Transport{ 36 Proxy: http.ProxyFromEnvironment, 37 DialContext: (&net.Dialer{ 38 Timeout: 30 * time.Second, // 限制建立TCP连接的时间 39 KeepAlive: 30 * time.Second, // 保持连接的超时时间 40 }).DialContext, 41 IdleConnTimeout: 30 * time.Second, // 空闲(keep-alive)连接在关闭之前保持空闲的时长 42 TLSHandshakeTimeout: 10 * time.Second, // 限制 TLS握手的时间 43 ResponseHeaderTimeout: 10 * time.Second, // 限制读取response header的时间,默认 timeout + 5*time.Second 44 ExpectContinueTimeout: 1 * time.Second, // 限制client在发送包含 Expect: 100-continue的header到收到继续发送body的response之间的时间等待。 45 MaxIdleConns: 100, // 所有host的连接池最大连接数量,默认无穷大 46 MaxIdleConnsPerHost: DefaultConnections, // 每个host的连接池最大空闲连接数,默认2 47 MaxConnsPerHost: DefaultMaxConnections, // 每个host的最大连接数量 48 //ForceAttemptHTTP2: true, 49 } 50 51 func defaultClient() *http.Client { 52 return &http.Client{ 53 Transport: DefaultRoundTripper, 54 Timeout: DefaultTimeout, //设置超时时间 55 } 56 }