Documentation ¶
Index ¶
- Variables
- func Backoff(execFunc func() (*http.Response, error), configureFuncs ...ConfigureFunc) error
- type ConfigureFunc
- type DnsResolver
- type HttpClient
- func (c *HttpClient) Cookies(u *netUrl.URL) []*http.Cookie
- func (c *HttpClient) Do(req *http.Request) (*Response, error)
- func (c *HttpClient) Get(header map[string]string, url string, params map[string]string) (*Response, error)
- func (c *HttpClient) Post(header map[string]string, url, contentType string, body []byte) (*Response, error)
- func (c *HttpClient) PostForm(header map[string]string, url string, params map[string]string) (*Response, error)
- type HttpClientConfig
- type Options
- type Response
- type RetryAfterFunc
- type RetryConditionFunc
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultHttpClient = &HttpClient{client: http.DefaultClient}
View Source
var DefaultHttpClientConfig = &HttpClientConfig{ TimeoutMs: 30000, MaxRetry: 0, RetryWaitTimeMs: 0, MaxRetryWaitTimeMs: 0, AllowRedirect: false, KeepAliveMs: 30000, MaxIdleConns: 100, MaxIdleConnsPerHost: 0, IdleConnTimeoutMs: 90000, TLSHandshakeTimeoutMs: 10000, }
Functions ¶
Types ¶
type ConfigureFunc ¶
type ConfigureFunc func(options *Options)
func MaxRetries ¶
func MaxRetries(value int) ConfigureFunc
func MaxRetryWaitTime ¶
func MaxRetryWaitTime(value time.Duration) ConfigureFunc
func RetryAfterFun ¶
func RetryAfterFun(retryAfterFunc RetryAfterFunc) ConfigureFunc
func RetryConditions ¶
func RetryConditions(conditions []RetryConditionFunc) ConfigureFunc
func RetryWaitTime ¶
func RetryWaitTime(value time.Duration) ConfigureFunc
type DnsResolver ¶
type DnsResolver struct { TTL time.Duration // default 5 min. // contains filtered or unexported fields }
func (*DnsResolver) GetAllEntities ¶
func (r *DnsResolver) GetAllEntities() []*cacheEntity
func (*DnsResolver) LookupHost ¶
type HttpClient ¶
type HttpClient struct { MaxRetry int RetryWaitTime time.Duration MaxRetryWaitTime time.Duration AllowRedirect bool MaxAllowRedirects int // Custom parse response HTTP Retry-After header. // See: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html // e.g. Retry-After: Fri, 31 Dec 1999 23:59:59 GMT // e.g. Retry-After: 120 RetryAfterFunc RetryAfterFunc // Custom judge response is need to retry. // you can implement your custom strategy, for example: response status code is not 200. RetryConditions []RetryConditionFunc // contains filtered or unexported fields }
HttpClient struct wrapper http client, provides some new feature. 1. Local DNS Cache. 2. Retry Exponential Backoff And Jitter Strategy. See: https://aws.amazon.com/cn/blogs/architecture/exponential-backoff-and-jitter/ 3. Multi-Goroutine Download. 4. Allow Custom Max Redirects.
func NewHttpClient ¶
func NewHttpClient(config *HttpClientConfig) (*HttpClient, error)
type HttpClientConfig ¶
type HttpClientConfig struct { TimeoutMs int64 // default timeout 30 seconds, contain connection timeout and request timeout. MaxRetry int // default not retry. RetryWaitTimeMs int64 MaxRetryWaitTimeMs int64 AllowRedirect bool MaxAllowRedirects int // default allow 10 redirects. KeepAliveMs int64 // default keep-alive time is 30 seconds. MaxIdleConns int // default max idle connections is 100. MaxIdleConnsPerHost int // default per-host max idle connections is 0, no limit. IdleConnTimeoutMs int // default idle connections timeout is 90 seconds. TLSHandshakeTimeoutMs int // default TLS hand shake timeout is 10 seconds. ProxyUrl string // support http, https, socks proxy. ProxyUname string ProxyPasswd string }
type RetryAfterFunc ¶
Custom parse response HTTP Retry-After header. If Retry-After time greater than config max retry wait time, use config max retry wait time. See: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
Click to show internal directories.
Click to hide internal directories.