don't replace existing client
This commit is contained in:
parent
deb946cf22
commit
8a740fe634
1 changed files with 8 additions and 12 deletions
20
scraper.go
20
scraper.go
|
|
@ -118,14 +118,12 @@ func (s *Scraper) SetProxy(proxyAddr string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.client = &http.Client{
|
s.client.Transport = &http.Transport{
|
||||||
Transport: &http.Transport{
|
Proxy: http.ProxyURL(urlproxy),
|
||||||
Proxy: http.ProxyURL(urlproxy),
|
TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper),
|
||||||
TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper),
|
DialContext: (&net.Dialer{
|
||||||
DialContext: (&net.Dialer{
|
Timeout: s.client.Timeout,
|
||||||
Timeout: s.client.Timeout,
|
}).DialContext,
|
||||||
}).DialContext,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -141,10 +139,8 @@ func (s *Scraper) SetProxy(proxyAddr string) error {
|
||||||
}
|
}
|
||||||
if contextDialer, ok := dialSocksProxy.(proxy.ContextDialer); ok {
|
if contextDialer, ok := dialSocksProxy.(proxy.ContextDialer); ok {
|
||||||
dialContext := contextDialer.DialContext
|
dialContext := contextDialer.DialContext
|
||||||
s.client = &http.Client{
|
s.client.Transport = &http.Transport{
|
||||||
Transport: &http.Transport{
|
DialContext: dialContext,
|
||||||
DialContext: dialContext,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return errors.New("failed type assertion to DialContext")
|
return errors.New("failed type assertion to DialContext")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue