mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-13 09:12:28 +08:00
feat: add Timeout config for http client
This commit is contained in:
@@ -102,6 +102,7 @@ type HttpRequest struct {
|
|||||||
|
|
||||||
// HttpClientConfig contains some configurations for http client
|
// HttpClientConfig contains some configurations for http client
|
||||||
type HttpClientConfig struct {
|
type HttpClientConfig struct {
|
||||||
|
Timeout time.Duration
|
||||||
SSLEnabled bool
|
SSLEnabled bool
|
||||||
TLSConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
Compressed bool
|
Compressed bool
|
||||||
@@ -113,9 +114,10 @@ type HttpClientConfig struct {
|
|||||||
|
|
||||||
// defaultHttpClientConfig defalut client config.
|
// defaultHttpClientConfig defalut client config.
|
||||||
var defaultHttpClientConfig = &HttpClientConfig{
|
var defaultHttpClientConfig = &HttpClientConfig{
|
||||||
|
Timeout: 50 * time.Second,
|
||||||
Compressed: false,
|
Compressed: false,
|
||||||
HandshakeTimeout: 20 * time.Second,
|
HandshakeTimeout: 10 * time.Second,
|
||||||
ResponseTimeout: 40 * time.Second,
|
ResponseTimeout: 10 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
// HttpClient is used for sending http request.
|
// HttpClient is used for sending http request.
|
||||||
@@ -131,6 +133,7 @@ type HttpClient struct {
|
|||||||
func NewHttpClient() *HttpClient {
|
func NewHttpClient() *HttpClient {
|
||||||
client := &HttpClient{
|
client := &HttpClient{
|
||||||
Client: &http.Client{
|
Client: &http.Client{
|
||||||
|
Timeout: defaultHttpClientConfig.Timeout,
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
TLSHandshakeTimeout: defaultHttpClientConfig.HandshakeTimeout,
|
TLSHandshakeTimeout: defaultHttpClientConfig.HandshakeTimeout,
|
||||||
ResponseHeaderTimeout: defaultHttpClientConfig.ResponseTimeout,
|
ResponseHeaderTimeout: defaultHttpClientConfig.ResponseTimeout,
|
||||||
|
|||||||
Reference in New Issue
Block a user