waitForSOCKS5 waits for the SOCKS5 proxy to be available
(ctx context.Context, port int, timeout time.Duration)
| 86 | |
| 87 | // waitForSOCKS5 waits for the SOCKS5 proxy to be available |
| 88 | func waitForSOCKS5(ctx context.Context, port int, timeout time.Duration) error { |
| 89 | deadline := time.Now().Add(timeout) |
| 90 | |
| 91 | for time.Now().Before(deadline) { |
| 92 | select { |
| 93 | case <-ctx.Done(): |
| 94 | return ctx.Err() |
| 95 | default: |
| 96 | } |
| 97 | |
| 98 | // Try to connect to the SOCKS5 proxy |
| 99 | proxyURL, _ := url.Parse("socks5://localhost:8080") |
| 100 | client := &http.Client{ |
| 101 | Transport: &http.Transport{ |
| 102 | Proxy: http.ProxyURL(proxyURL), |
| 103 | }, |
| 104 | Timeout: 5 * time.Second, |
| 105 | } |
| 106 | |
| 107 | // Try a simple HTTP request through the proxy |
| 108 | resp, err := client.Get("http://httpbin.org/ip") |
| 109 | if err == nil { |
| 110 | resp.Body.Close() |
| 111 | return nil |
| 112 | } |
| 113 | |
| 114 | time.Sleep(5 * time.Second) |
| 115 | } |
| 116 | |
| 117 | return context.DeadlineExceeded |
| 118 | } |
| 119 | |
| 120 | // testHTTPTraffic tests that HTTP requests work through the proxy |
| 121 | func testHTTPTraffic() error { |
no outgoing calls
no test coverage detected