From 824dba2a9fadcf4e575cd8b3cadc2d190be5996d Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Fri, 17 Nov 2023 13:50:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BA=94=E7=94=A8=E5=95=86=E5=BA=97?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=A2=9E=E5=8A=A0=E8=B6=85=E6=97=B6=E6=97=B6?= =?UTF-8?q?=E9=97=B4=20(#2983)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/utils/http/get.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/backend/utils/http/get.go b/backend/utils/http/get.go index 4cecce116..223a05093 100644 --- a/backend/utils/http/get.go +++ b/backend/utils/http/get.go @@ -2,7 +2,9 @@ package http import ( "context" + "errors" "github.com/1Panel-dev/1Panel/backend/buserr" + "net" "net/http" "strings" "time" @@ -10,8 +12,15 @@ import ( func GetHttpRes(url string) (*http.Response, error) { client := &http.Client{ + Timeout: time.Second * 300, Transport: &http.Transport{ - IdleConnTimeout: 10 * time.Second, + DialContext: (&net.Dialer{ + Timeout: 60 * time.Second, + KeepAlive: 60 * time.Second, + }).DialContext, + TLSHandshakeTimeout: 5 * time.Second, + ResponseHeaderTimeout: 10 * time.Second, + IdleConnTimeout: 15 * time.Second, }, } @@ -22,7 +31,7 @@ func GetHttpRes(url string) (*http.Response, error) { resp, err := client.Do(req) if err != nil { - if err == context.DeadlineExceeded { + if errors.Is(err, context.DeadlineExceeded) { return nil, buserr.WithMap("ErrHttpReqTimeOut", map[string]interface{}{"err": err.Error()}, err) } else { if strings.Contains(err.Error(), "no such host") {