Documentation
¶
Index ¶
- Constants
- func New(opts ...Option) *fasthttp.Client
- type Option
- func WithConfigureClient(configureClient func(hc *fasthttp.HostClient) error) Option
- func WithConnPoolStrategy(connPoolStrategy fasthttp.ConnPoolStrategyType) Option
- func WithDial(dial fasthttp.DialFunc) Option
- func WithDialDualStack(dialDualStack bool) Option
- func WithDialTimeout(dialTimeout fasthttp.DialFuncWithTimeout) Option
- func WithDisableHeaderNamesNormalizing(disableHeaderNamesNormalizing bool) Option
- func WithDisablePathNormalizing(disablePathNormalizing bool) Option
- func WithMaxConnDuration(maxConnDuration time.Duration) Option
- func WithMaxConnWaitTimeout(maxConnWaitTimeout time.Duration) Option
- func WithMaxConnsPerHost(maxConnsPerHost int) Option
- func WithMaxIdemponentCallAttempts(maxIdemponentCallAttempts int) Option
- func WithMaxIdleConnDuration(maxIdleConnDuration time.Duration) Option
- func WithMaxResponseBodySize(maxResponseBodySize int) Option
- func WithName(name string) Option
- func WithNoDefaultUserAgentHeader(noDefaultUserAgentHeader bool) Option
- func WithReadBufferSize(readBufferSize int) Option
- func WithReadTimeout(readTimeout time.Duration) Option
- func WithRetryIfErr(retryIfErr fasthttp.RetryIfErrFunc) Option
- func WithStreamResponseBody(streamResponseBody bool) Option
- func WithTLSConfig(tlsConfig *tls.Config) Option
- func WithTransport(transport fasthttp.RoundTripper) Option
- func WithWriteBufferSize(writeBufferSize int) Option
- func WithWriteTimeout(writeTimeout time.Duration) Option
Constants ¶
const ( // Client name. Used in User-Agent request header. DefaultClientName = "microcore" // Maximum number of connections per each host which may be established. DefaultClientMaxConnsPerHost = 512 // Idle keep-alive connections are closed after this duration. DefaultClientMaxIdleConnDuration = 10 * time.Second // Keep-alive connections are closed after this duration. DefaultClientMaxConnDuration = time.Duration(0) // Maximum number of attempts for idempotent calls. DefaultClientMaxIdemponentCallAttempts = 5 // Per-connection buffer size for responses' reading. // This also limits the maximum header size. DefaultClientReadBufferSize = 4096 // Per-connection buffer size for requests' writing. DefaultClientWriteBufferSize = 4096 // Maximum duration for full response reading (including body). DefaultClientReadTimeout = 10 * time.Second // Maximum duration for full request writing (including body). DefaultClientWriteTimeout = 10 * time.Second // Header names are passed as-is without normalization // if this option is set. DefaultClientDisableHeaderNamesNormalizing = false // Path values are sent as-is without normalization. DefaultClientDisablePathNormalizing = false )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
func WithConfigureClient ¶
func WithConfigureClient(configureClient func(hc *fasthttp.HostClient) error) Option
ConfigureClient configures the fasthttp.HostClient.
func WithConnPoolStrategy ¶
func WithConnPoolStrategy(connPoolStrategy fasthttp.ConnPoolStrategyType) Option
Connection pool strategy. Can be either LIFO or FIFO (default).
func WithDial ¶
Callback for establishing new connections to hosts.
Note that if Dial is set instead of DialTimeout, Dial will ignore Request timeout. If you want the tcp dial process to account for request timeouts, use DialTimeout instead.
If not set, DialTimeout is used.
func WithDialDualStack ¶
Attempt to connect to both ipv4 and ipv6 addresses if set to true.
This option is used only if default TCP dialer is used, i.e. if Dial is blank.
By default client connects only to ipv4 addresses, since unfortunately ipv6 remains broken in many networks worldwide :)
func WithDialTimeout ¶
func WithDialTimeout(dialTimeout fasthttp.DialFuncWithTimeout) Option
Callback for establishing new connections to hosts.
Default DialTimeout is used if not set.
func WithDisableHeaderNamesNormalizing ¶
Header names are passed as-is without normalization if this option is set.
Disabled header names' normalization may be useful only for proxying responses to other clients expecting case-sensitive header names. See https://github.com/valyala/fasthttp/issues/57 for details.
By default request and response header names are normalized, i.e. The first letter and the first letters following dashes are uppercased, while all the other letters are lowercased. Examples:
- HOST -> Host
- content-type -> Content-Type
- cONTENT-lenGTH -> Content-Length
func WithDisablePathNormalizing ¶
Path values are sent as-is without normalization.
Disabled path normalization may be useful for proxying incoming requests to servers that are expecting paths to be forwarded as-is.
By default path values are normalized, i.e. extra slashes are removed, special characters are encoded.
func WithMaxConnDuration ¶
Keep-alive connections are closed after this duration.
By default connection duration is unlimited.
func WithMaxConnWaitTimeout ¶
Maximum duration for waiting for a free connection.
By default will not waiting, return ErrNoFreeConns immediately.
func WithMaxConnsPerHost ¶
Maximum number of connections per each host which may be established.
DefaultMaxConnsPerHost is used if not set.
func WithMaxIdemponentCallAttempts ¶
Maximum number of attempts for idempotent calls.
DefaultMaxIdemponentCallAttempts is used if not set.
func WithMaxIdleConnDuration ¶
Idle keep-alive connections are closed after this duration.
By default idle connections are closed after DefaultMaxIdleConnDuration.
func WithMaxResponseBodySize ¶
Maximum response body size.
The client returns ErrBodyTooLarge if this limit is greater than 0 and response body is greater than the limit.
By default response body size is unlimited.
func WithName ¶
Client name. Used in User-Agent request header.
Default client name is used if not set.
func WithNoDefaultUserAgentHeader ¶
NoDefaultUserAgentHeader when set to true, causes the default User-Agent header to be excluded from the Request.
func WithReadBufferSize ¶
Per-connection buffer size for responses' reading. This also limits the maximum header size.
Default buffer size is used if 0.
func WithReadTimeout ¶
Maximum duration for full response reading (including body).
By default response read timeout is unlimited.
func WithRetryIfErr ¶
func WithRetryIfErr(retryIfErr fasthttp.RetryIfErrFunc) Option
When the client encounters an error during a request, the behavior—whether to retry and whether to reset the request timeout—should be determined based on the return value of this field. This field is only effective within the range of MaxIdemponentCallAttempts.
func WithStreamResponseBody ¶
StreamResponseBody enables response body streaming.
func WithTransport ¶
func WithTransport(transport fasthttp.RoundTripper) Option
Transport defines a transport-like mechanism that wraps every request/response.
func WithWriteBufferSize ¶
Per-connection buffer size for requests' writing.
Default buffer size is used if 0.
func WithWriteTimeout ¶
Maximum duration for full request writing (including body).
By default request write timeout is unlimited.