mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-24 02:59:16 +08:00
feat: 应用商店请求增加超时时间 (#2983)
This commit is contained in:
parent
7e6c39bb08
commit
824dba2a9f
@ -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") {
|
||||
|
Loading…
Reference in New Issue
Block a user