Support https proxy
This commit is contained in:
parent
c299d7f479
commit
6414a834ea
1 changed files with 5 additions and 3 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package twitterscraper
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
|
|
@ -38,8 +39,8 @@ func WithReplies(b bool) *Scraper {
|
|||
|
||||
// SetProxy set http proxy in the format `http://HOST:PORT`
|
||||
func (s *Scraper) SetProxy(proxy string) error {
|
||||
if !strings.HasPrefix(proxy, "http://") {
|
||||
return errors.New("only support http protocol")
|
||||
if !strings.HasPrefix(proxy, "http") {
|
||||
return errors.New("only support http(s) protocol")
|
||||
}
|
||||
urlproxy, err := url.Parse(proxy)
|
||||
if err != nil {
|
||||
|
|
@ -48,6 +49,7 @@ func (s *Scraper) SetProxy(proxy string) error {
|
|||
s.client = &http.Client{
|
||||
Transport: &http.Transport{
|
||||
Proxy: http.ProxyURL(urlproxy),
|
||||
TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper),
|
||||
DialContext: (&net.Dialer{
|
||||
Timeout: 10 * time.Second,
|
||||
}).DialContext,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue