MCPcopy Create free account
hub / github.com/dan-v/lambda-nat-proxy / waitForSOCKS5

Function waitForSOCKS5

test/e2e/basic_test.go:88–118  ·  view source on GitHub ↗

waitForSOCKS5 waits for the SOCKS5 proxy to be available

(ctx context.Context, port int, timeout time.Duration)

Source from the content-addressed store, hash-verified

86
87// waitForSOCKS5 waits for the SOCKS5 proxy to be available
88func 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
121func testHTTPTraffic() error {

Callers 1

TestBasicConnectivityFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected