From 2d41663dbd87c8ab8ea0121dfa4e85cfd19c2bcf Mon Sep 17 00:00:00 2001 From: niuhuan Date: Sat, 19 Mar 2022 14:01:51 +0800 Subject: [PATCH] Supported both DialContext and proxy --- go/pikapika/client.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/go/pikapika/client.go b/go/pikapika/client.go index 671b38a..ee1f139 100644 --- a/go/pikapika/client.go +++ b/go/pikapika/client.go @@ -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 }