|
|
@@ -34,12 +34,20 @@ func checkRedirect(req *http.Request, via []*http.Request) error {
|
|
|
}
|
|
|
|
|
|
func InitHttpClient() {
|
|
|
+ transport := &http.Transport{
|
|
|
+ MaxIdleConns: common.RelayMaxIdleConns,
|
|
|
+ MaxIdleConnsPerHost: common.RelayMaxIdleConnsPerHost,
|
|
|
+ ForceAttemptHTTP2: true,
|
|
|
+ }
|
|
|
+
|
|
|
if common.RelayTimeout == 0 {
|
|
|
httpClient = &http.Client{
|
|
|
+ Transport: transport,
|
|
|
CheckRedirect: checkRedirect,
|
|
|
}
|
|
|
} else {
|
|
|
httpClient = &http.Client{
|
|
|
+ Transport: transport,
|
|
|
Timeout: time.Duration(common.RelayTimeout) * time.Second,
|
|
|
CheckRedirect: checkRedirect,
|
|
|
}
|
|
|
@@ -84,6 +92,9 @@ func NewProxyHttpClient(proxyURL string) (*http.Client, error) {
|
|
|
case "http", "https":
|
|
|
client := &http.Client{
|
|
|
Transport: &http.Transport{
|
|
|
+ MaxIdleConns: common.RelayMaxIdleConns,
|
|
|
+ MaxIdleConnsPerHost: common.RelayMaxIdleConnsPerHost,
|
|
|
+ ForceAttemptHTTP2: true,
|
|
|
Proxy: http.ProxyURL(parsedURL),
|
|
|
},
|
|
|
CheckRedirect: checkRedirect,
|
|
|
@@ -116,6 +127,9 @@ func NewProxyHttpClient(proxyURL string) (*http.Client, error) {
|
|
|
|
|
|
client := &http.Client{
|
|
|
Transport: &http.Transport{
|
|
|
+ MaxIdleConns: common.RelayMaxIdleConns,
|
|
|
+ MaxIdleConnsPerHost: common.RelayMaxIdleConnsPerHost,
|
|
|
+ ForceAttemptHTTP2: true,
|
|
|
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
|
|
return dialer.Dial(network, addr)
|
|
|
},
|