Skip to content

Commit

Permalink
Supported both DialContext and proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
niuhuan committed Mar 19, 2022
1 parent 2a2cda8 commit 2d41663
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions go/pikapika/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
}

Expand Down

0 comments on commit 2d41663

Please sign in to comment.