From 4d21e81263f17990ff008ff6f436c71ae5cd352d Mon Sep 17 00:00:00 2001 From: dudaodong Date: Tue, 4 Jun 2024 16:28:00 +0800 Subject: [PATCH] feat: add Timeout config for http client --- netutil/http.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/netutil/http.go b/netutil/http.go index c9269da..d0aaa68 100644 --- a/netutil/http.go +++ b/netutil/http.go @@ -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,