package utils import ( "context" // "crypto/tls" "fmt" "io" "net/http" // "net/url" "time" ) type RetryConfig struct { MaxRetries int BaseDelay time.Duration MaxDelay time.Duration } type RetryableHTTPRequestImpl struct { client *http.Client config RetryConfig } func NewRetryableHTTPRequest(config RetryConfig) *RetryableHTTPRequestImpl { return NewRetryableHTTPRequestWithProxy(config, "") } func NewRetryableHTTPRequestWithProxy(config RetryConfig, proxyURL string) *RetryableHTTPRequestImpl { // var transport *http.Transport // if proxyURL != "" { // proxyUrl, err := url.Parse(proxyURL) // if err != nil { // panic(fmt.Sprintf("Failed to parse proxy URL '%s': %v", proxyURL, err)) // } // transport = &http.Transport{ // Proxy: http.ProxyURL(proxyUrl), // TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // } // } client := &http.Client{ Timeout: 30 * time.Second, // Transport: transport, } return &RetryableHTTPRequestImpl{ client: client, config: config, } } func (s *RetryableHTTPRequestImpl) RetryableHTTPRequest(ctx context.Context, url, method string, body io.Reader, headers []http.Header) (*http.Response, error) { var lastErr error for attempt := 0; attempt <= s.config.MaxRetries; attempt++ { req, err := http.NewRequestWithContext(ctx, method, url, body) if err != nil { return nil, fmt.Errorf("failed to create request: %w", err) } req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36") for _, header := range headers { req.Header.Set(header.Get("Key"), header.Get("Value")) } resp, err := s.client.Do(req) if err != nil { lastErr = err fmt.Printf("Request attempt %d failed: %v\n", attempt+1, err) } else if resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices { // Success return resp, nil } else if resp.StatusCode == http.StatusTooManyRequests { // 429 Too Many Requests - retry with backoff resp.Body.Close() lastErr = fmt.Errorf("rate limited: %d %s", resp.StatusCode, resp.Status) fmt.Printf("Request attempt %d failed with status %d (rate limited)\n", attempt+1, resp.StatusCode) } else { // All other errors (4xx, 5xx) - don't retry resp.Body.Close() return nil, fmt.Errorf("request failed %d: %s", resp.StatusCode, resp.Status) } // max attempts for now = 3 if attempt < s.config.MaxRetries { // Increment delay by 2 seconds for each attempt delay := time.Second * time.Duration(2*(attempt+1)) // 2s, 4s, 6s, ... // Cap the delay to MaxDelay if set if s.config.MaxDelay > 0 && delay > s.config.MaxDelay { delay = s.config.MaxDelay } fmt.Printf("Retrying in %v... (attempt %d/%d)\n", delay, attempt+1, s.config.MaxRetries) select { case <-ctx.Done(): return nil, ctx.Err() case <-time.After(delay): // Continue to next attempt } } } return nil, fmt.Errorf("all retry attempts failed, last error: %w", lastErr) } // 5.10.245.81:80 // 172.67.70.206:80 // 190.93.245.33:80 // 185.221.160.176:80 // 141.101.123.156:80 // 103.21.244.129:80 // 103.169.142.59:80 // 172.67.81.185:80 // 37.18.73.60:5566 // 209.38.83.56:1088 // 89.169.36.109:1080 // 103.21.244.248:80 // 172.67.70.92:80 // 172.67.88.34:80 // 141.101.120.38:80 // 172.67.75.255:80 // 172.67.75.171:80 // 45.131.4.157:80 // 141.101.121.208:80 // 141.101.120.70:80 // 103.21.244.70:80 // 103.21.244.140:80 // 103.21.244.138:80 // 154.16.146.43:80 // 128.199.202.122:3128 // 160.153.0.28:80 // 185.170.166.31:80 // 172.67.70.95:80 // 141.101.123.91:80 // 141.101.121.81:80 // 141.101.121.71:80 // 141.101.120.224:80 // 192.111.137.35:4145 // 45.12.31.20:80 // 103.21.244.150:80 // 103.21.244.214:80 // 103.21.244.29:80 // 195.85.23.88:80 // 23.227.39.134:80 // 66.42.224.229:41679 // 172.67.73.123:80 // 79.110.200.27:8000 // 5.182.34.33:80 // 103.21.244.174:80 // 172.67.75.203:80 // 141.101.122.150:80 // 141.101.120.35:80 // 175.47.237.95:6128 // 103.21.244.185:80 // 141.101.122.86:80 // 141.101.121.89:80 // 103.21.244.105:80 // 103.21.244.234:80 // 172.67.70.20:80 // 163.223.172.27:1080 // 172.67.84.128:80 // 103.21.244.57:80 // 31.43.179.191:80 // 173.245.59.61:80 // 141.101.120.48:80 // 185.162.230.19:80 // 172.67.172.150:80 // 159.112.235.63:80 // 172.64.40.184:80 // 103.21.244.55:80 // 103.21.244.49:80 // 172.67.70.228:80 // 103.21.244.8:80 // 66.235.200.77:80 // 45.85.119.147:80 // 172.67.177.231:80 // 173.245.49.28:80 // 110.232.92.49:8080 // 212.183.88.212:80 // 108.162.193.73:80 // 185.238.228.29:80 // 172.67.127.8:80 // 164.38.155.86:80 // 160.153.0.18:80 // 141.101.122.119:80 // 103.21.244.186:80 // 172.67.172.162:80 // 8.218.39.40:10800 // 47.237.132.101:60031 // 222.59.173.105:44193 // 143.110.190.60:1080 // 152.53.194.55:32059 // 115.187.50.40:5678 // 171.254.219.180:1080 // 103.165.157.155:8080 // 45.233.169.57:999 // 222.59.173.105:45035 // 202.40.179.18:4145 // 170.79.181.188:60606 // 37.186.66.36:3629 // 104.200.152.30:4145 // 106.13.58.110:8888 // 202.40.181.220:31247 // 43.135.36.240:80 // 103.82.27.107:10001 // 192.252.209.158:4145 // 142.54.236.97:4145 // 142.54.239.1:4145 // 184.170.245.148:4145 // 68.71.247.130:4145 // 72.195.34.58:4145 // 172.65.90.2:80 // 172.65.90.0:80 // 36.138.53.26:10019 // 183.215.23.242:9091 // 45.131.7.34:80 // 141.101.120.230:80 // 172.64.78.193:80 // 141.101.122.9:80 // 103.21.244.80:80 // 103.21.244.147:80 // 103.21.244.106:80 // 103.21.244.16:80 // 199.34.229.210:80 // 141.101.90.98:80 // 172.67.70.127:80 // 103.21.244.221:80 // 172.67.171.203:80 // 172.67.181.188:80 // 72.195.101.99:4145 // 141.101.120.106:80 // 103.21.244.180:80 // 103.21.244.102:80 // 172.67.70.233:80 // 108.162.193.107:80 // 45.131.208.112:80 // 154.194.12.195:80 // 69.84.182.23:80 // 141.101.120.128:80 // 141.101.120.149:80 // 141.101.120.232:80 // 141.101.120.6:80 // 172.67.98.18:80 // 141.101.113.20:80 // 208.65.90.21:4145 // 198.177.254.131:4145 // 142.54.237.38:4145 // 192.252.220.89:4145 // 199.187.210.54:4145 // 199.102.105.242:4145 // 199.102.107.145:4145 // 198.8.84.3:4145 // 98.182.171.161:4145 // 192.111.129.150:4145 // 184.170.248.5:4145 // 98.188.47.150:4145 // 125.228.94.232:4145 // 125.228.94.153:4145 // 185.162.229.219:80 // 103.21.244.22:80 // 172.64.89.97:80 // 103.21.244.54:80 // 103.21.244.37:80 // 141.101.123.225:80 // 103.21.244.168:80 // 103.21.244.149:80 // 103.21.244.100:80 // 103.21.244.24:80 // 23.227.39.209:80 // 172.67.83.15:80 // 45.131.4.241:80 // 141.101.120.201:80 // 172.67.191.237:80 // 172.67.127.188:80 // 103.21.244.92:80 // 103.160.204.22:80 // 220.197.44.36:3128 // 39.185.41.193:5911 // 23.227.39.121:80 // 139.162.78.109:80 // 188.114.99.144:80 // 45.131.5.37:80 // 45.131.4.250:80 // 23.227.39.65:80 // 141.101.121.191:80 // 172.67.188.16:80 // 172.67.254.148:80 // 221.1.104.177:7302 // 222.59.173.105:44008 // 103.21.244.83:80 // 172.64.149.1:80 // 45.12.30.22:80 // 222.59.173.105:44027 // 172.64.149.26:80 // 103.21.244.46:80 // 45.12.31.242:80 // 23.227.38.195:80 // 172.67.177.162:80 // 103.160.204.200:80 // 172.67.70.129:80 // 141.101.123.245:80 // 185.162.230.117:80 // 185.162.230.183:80 // 69.61.200.104:36181 // 208.65.90.3:4145 // 72.223.188.92:4145 // 192.252.214.17:4145 // 68.71.242.118:4145 // 192.252.210.233:4145 // 107.181.161.81:4145 // 107.181.168.145:4145 // 206.220.175.2:4145 // 72.37.217.3:4145 // 192.252.208.70:14282 // 70.166.167.55:57745 // 192.111.137.37:18762 // 98.188.47.132:4145 // 62.99.138.162:80 // 172.64.90.186:80 // 172.67.74.57:80 // 45.131.6.67:80 // 141.101.122.37:80 // 103.21.244.134:80 // 172.64.155.71:80 // 5.182.34.139:80 // 45.131.6.31:80 // 141.101.121.21:80 // 141.101.120.190:80 // 103.21.244.161:80 // 103.21.244.156:80 // 103.21.244.151:80 // 172.64.89.0:80 // 58.216.109.17:800 // 58.241.88.18:800 // 36.147.78.166:80 // 170.244.26.36:8888 // 170.244.25.52:8888 // 170.244.26.206:8888 // 36.138.53.26:10017 // 201.148.32.162:80 // 203.19.38.114:1080 // 31.43.179.204:80 // 45.12.31.50:80 // 170.244.27.142:8888 // 170.244.26.195:8888 // 170.244.27.58:8888 // 170.244.27.61:8888 // 170.244.27.150:8888 // 47.243.94.125:1080 // 40.177.65.8:80 // 47.57.13.107:80 // 194.158.203.14:80 // 194.219.134.234:80 // 103.21.244.51:80 // 103.21.244.160:80 // 103.21.244.144:80 // 213.33.126.130:80 // 103.21.244.69:80 // 103.21.244.192:80 // 103.21.244.133:80 // 141.193.213.189:80 // 68.71.254.6:4145 // 185.221.160.21:80 // 188.114.99.97:80 // 63.141.128.94:80 // 141.193.213.213:80 // 185.162.228.234:80 // 213.143.113.82:80 // 154.194.12.207:80 // 189.203.181.34:1080 // 202.144.134.150:5678 // 190.242.157.215:8080 // 72.49.49.11:31034 // 142.54.237.34:4145 // 68.71.249.153:48606 // 192.252.209.155:14455 // 192.252.216.86:4145 // 142.54.229.249:4145 // 209.97.150.167:8080 // 192.252.220.92:17328 // 98.178.72.21:10919 // 144.124.228.87:1080 // 183.240.46.42:80 // 32.223.6.94:80 // 192.252.214.20:15864 // 198.177.252.24:4145 // 192.252.208.67:14287 // 198.8.94.170:4145 // 68.71.241.33:4145 // 98.181.137.83:4145 // 45.12.30.139:80 // 103.21.244.97:80 // 65.1.148.157:80 // 199.58.184.97:4145 // 141.101.120.148:80 // 185.238.228.77:80 // 172.67.202.134:80 // 172.67.182.49:80 // 45.131.210.112:80 // 141.101.120.100:80 // 103.21.244.59:80 // 103.21.244.189:80 // 103.21.244.154:80 // 103.21.244.23:80 // 173.245.49.40:80 // 82.200.235.134:38191 // 43.224.118.89:2626 // 119.148.47.226:16464 // 211.230.49.122:3128 // 62.171.159.232:8888 // 115.127.112.34:1080 // 185.191.236.162:3128 // 41.223.119.156:3128 // 103.138.123.242:8082 // 121.169.46.116:1090 // 185.145.185.218:8080 // 45.166.93.113:999 // 163.53.204.178:9813 // 181.224.226.154:8080