1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

feat: add Timeout config for http client

This commit is contained in:
dudaodong
2024-06-04 16:28:00 +08:00
parent ce2397422e
commit 4d21e81263

View File

@@ -102,6 +102,7 @@ type HttpRequest struct {
// HttpClientConfig contains some configurations for http client
type HttpClientConfig struct {
Timeout time.Duration
SSLEnabled bool
TLSConfig *tls.Config
Compressed bool
@@ -113,9 +114,10 @@ type HttpClientConfig struct {
// defaultHttpClientConfig defalut client config.
var defaultHttpClientConfig = &HttpClientConfig{
Timeout: 50 * time.Second,
Compressed: false,
HandshakeTimeout: 20 * time.Second,
ResponseTimeout: 40 * time.Second,
HandshakeTimeout: 10 * time.Second,
ResponseTimeout: 10 * time.Second,
}
// HttpClient is used for sending http request.
@@ -131,6 +133,7 @@ type HttpClient struct {
func NewHttpClient() *HttpClient {
client := &HttpClient{
Client: &http.Client{
Timeout: defaultHttpClientConfig.Timeout,
Transport: &http.Transport{
TLSHandshakeTimeout: defaultHttpClientConfig.HandshakeTimeout,
ResponseHeaderTimeout: defaultHttpClientConfig.ResponseTimeout,