Supported both DialContext and proxy

This commit is contained in:
niuhuan 2022-03-19 14:01:51 +08:00
parent 2a2cda8933
commit 2d41663dbd
1 changed files with 26 additions and 0 deletions

View File

@ -62,6 +62,15 @@ func changeProxyUrl(urlStr string) bool {
return dialer.DialContext(ctx, network, addr)
},
}
imageHttpClient.Transport = &http.Transport{
TLSHandshakeTimeout: time.Second * 10,
ExpectContinueTimeout: time.Second * 10,
ResponseHeaderTimeout: time.Second * 10,
IdleConnTimeout: time.Second * 10,
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
return dialer.DialContext(ctx, network, addr)
},
}
return false
}
client.Transport = &http.Transport{
@ -84,6 +93,23 @@ func changeProxyUrl(urlStr string) bool {
return proxy.Dial(network, addr)
},
}
imageHttpClient.Transport = &http.Transport{
TLSHandshakeTimeout: time.Second * 10,
ExpectContinueTimeout: time.Second * 10,
ResponseHeaderTimeout: time.Second * 10,
IdleConnTimeout: time.Second * 10,
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
proxyUrl, err := url.Parse(urlStr)
if err != nil {
return nil, err
}
proxy, err := proxy.FromURL(proxyUrl, proxy.Direct)
if err != nil {
return nil, err
}
return proxy.Dial(network, addr)
},
}
return true
}