mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
set http connect timeout
This commit is contained in:
@@ -5,8 +5,10 @@ import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
@@ -42,12 +44,19 @@ func NewClient(authUrl string, timeout int, debug bool, insecure bool, certFile,
|
||||
|
||||
tr := &http.Transport{
|
||||
TLSClientConfig: tlsConf,
|
||||
DialContext: (&net.Dialer{
|
||||
Timeout: 5 * time.Second,
|
||||
}).DialContext,
|
||||
TLSHandshakeTimeout: 10 * time.Second,
|
||||
}
|
||||
|
||||
client := Client{authUrl: authUrl,
|
||||
timeout: timeout,
|
||||
debug: debug,
|
||||
httpconn: &http.Client{Transport: tr}}
|
||||
timeout: timeout,
|
||||
debug: debug,
|
||||
httpconn: &http.Client{
|
||||
Transport: tr,
|
||||
},
|
||||
}
|
||||
return &client
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -102,7 +103,11 @@ func GetAddrPort(urlStr string) (string, int, error) {
|
||||
|
||||
func GetClient(insecure bool) *http.Client {
|
||||
tr := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecure},
|
||||
DialContext: (&net.Dialer{
|
||||
Timeout: 5 * time.Second,
|
||||
}).DialContext,
|
||||
TLSHandshakeTimeout: 10 * time.Second,
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecure},
|
||||
}
|
||||
return &http.Client{Transport: tr}
|
||||
}
|
||||
@@ -116,7 +121,7 @@ func GetTimeoutClient(timeout time.Duration) *http.Client {
|
||||
var defaultHttpClient *http.Client
|
||||
|
||||
func init() {
|
||||
defaultHttpClient = GetTimeoutClient(time.Second * 10)
|
||||
defaultHttpClient = GetClient(true)
|
||||
}
|
||||
|
||||
func GetDefaultClient() *http.Client {
|
||||
|
||||
Reference in New Issue
Block a user