client/http/http_client.go
func Transport(options *Options) *http.Transport {
	if options.Timeout == 0 {
		options.Timeout = 30 * time.Second
	}
	if options.KeepAlive == 0 {
		options.KeepAlive = 30 * time.Second
	}
	if options.TLSHandshakeTimeout == 0 {
		options.TLSHandshakeTimeout = 30 * time.Second
	}

	netDialFunc := (&net.Dialer{
		Timeout:   options.Timeout,
		KeepAlive: options.KeepAlive,
	}).Dial

	dialFunc := netDialFunc

	if options.RetryTimeMax > 0 {
		retrySleepBaseNano := options.RetrySleepBase.Nanoseconds()
		if retrySleepBaseNano == 0 {
			retrySleepBaseNano = defaultRetrySleepBaseNano
		}
		retrySleepMaxNano := options.RetrySleepMax.Nanoseconds()
		if retrySleepMaxNano == 0 {
			retrySleepMaxNano = defaultRetrySleepMaxNano
		}
		dialFunc = func(network, address string) (conn net.Conn, err error) {
			var k int64 = 1
			sleepNano := retrySleepBaseNano
			start := time.Now()
			for time.Since(start.Add(-time.Duration(sleepNano))) < options.RetryTimeMax {
				conn, err = netDialFunc(network, address)
				if err != nil {
					sleepNano = retrySleepBaseNano * k
					if sleepNano <= 0 {
						break
					}
					time.Sleep(time.Duration(random.Int63n(func(x, y int64) int64 {
						if x < y {
							return x
						}
						return y
					}(retrySleepMaxNano, sleepNano))))
					k = 2 * k
					continue
				}
				return
			}
			return
		}
	}
	transport := &http.Transport{
		Proxy:               http.ProxyFromEnvironment,
		Dial:                dialFunc,
		TLSHandshakeTimeout: options.TLSHandshakeTimeout,
		TLSClientConfig:     &tls.Config{InsecureSkipVerify: options.TLSSkipVerify},
	}
	http2.ConfigureTransport(transport)
	return transport
}
func Transport(options *Options) *http.Transport {
	if options.Timeout == 0 {
		options.Timeout = 30 * time.Second
	}
	if options.KeepAlive == 0 {
		options.KeepAlive = 30 * time.Second
	}
	if options.TLSHandshakeTimeout == 0 {
		options.TLSHandshakeTimeout = 30 * time.Second
	}

	netDialFunc := (&net.Dialer{
		Timeout:   options.Timeout,
		KeepAlive: options.KeepAlive,
	}).Dial

	dialFunc := netDialFunc

	if options.RetryTimeMax > 0 {
		retrySleepBaseNano := options.RetrySleepBase.Nanoseconds()
		if retrySleepBaseNano == 0 {
			retrySleepBaseNano = defaultRetrySleepBaseNano
		}
		retrySleepMaxNano := options.RetrySleepMax.Nanoseconds()
		if retrySleepMaxNano == 0 {
			retrySleepMaxNano = defaultRetrySleepMaxNano
		}
		dialFunc = func(network, address string) (conn net.Conn, err error) {
			var k int64 = 1
			sleepNano := retrySleepBaseNano
			start := time.Now()
			for time.Since(start.Add(-time.Duration(sleepNano))) < options.RetryTimeMax {
				conn, err = netDialFunc(network, address)
				if err != nil {
					sleepNano = retrySleepBaseNano * k
					if sleepNano <= 0 {
						break
					}
					time.Sleep(time.Duration(random.Int63n(func(x, y int64) int64 {
						if x < y {
							return x
						}
						return y
					}(retrySleepMaxNano, sleepNano))))
					k = 2 * k
					continue
				}
				return
			}
			return
		}
	}
	transport := &http.Transport{
		Proxy:               http.ProxyFromEnvironment,
		Dial:                dialFunc,
		TLSHandshakeTimeout: options.TLSHandshakeTimeout,
		TLSClientConfig:     &tls.Config{InsecureSkipVerify: options.TLSSkipVerify},
	}
	http2.ConfigureTransport(transport)
	return transport
}
// Transport creates a net/http.Transport with options from Options.