Skip to content

Commit

Permalink
Fix checkProxy function
Browse files Browse the repository at this point in the history
  • Loading branch information
ahobsonsayers committed Sep 6, 2024
1 parent 6d7c56b commit aad12d6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions test/testutils/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func newProxyTransport(proxyListUrl string) (http.RoundTripper, error) {
return nil, fmt.Errorf("error downloading proxy list: %w", err)
}

proxyList = getWorkingProxies(proxyList, time.Second)
proxyList = getWorkingProxies(proxyList, 2*time.Second)
if len(proxyList) == 0 {
return nil, errors.New("none of the proxies in the proxy list are working")
}
Expand Down Expand Up @@ -132,12 +132,22 @@ func checkProxy(proxyUrl *url.URL, timeout time.Duration) bool {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

request, err := http.NewRequestWithContext(ctx, http.MethodGet, proxyUrl.String(), http.NoBody)
client := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(proxyUrl),
},
}

request, err := http.NewRequestWithContext(
ctx, http.MethodGet,
"https://example.com",
http.NoBody,
)
if err != nil {
panic(err)
}

response, err := http.DefaultClient.Do(request)
response, err := client.Do(request)
if err != nil || response.StatusCode >= 400 {
return false
}
Expand Down

0 comments on commit aad12d6

Please sign in to comment.