From 6414a834eacfa7b3e6bfcb3e59b8db81b4290a9a Mon Sep 17 00:00:00 2001 From: Alexander Sheiko Date: Sun, 13 Dec 2020 00:04:34 +0200 Subject: [PATCH] Support https proxy --- scraper.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scraper.go b/scraper.go index 4518391..28c9fe8 100644 --- a/scraper.go +++ b/scraper.go @@ -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 { @@ -47,7 +48,8 @@ func (s *Scraper) SetProxy(proxy string) error { } s.client = &http.Client{ Transport: &http.Transport{ - Proxy: http.ProxyURL(urlproxy), + Proxy: http.ProxyURL(urlproxy), + TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper), DialContext: (&net.Dialer{ Timeout: 10 * time.Second, }).DialContext,