(proxy string)
| 65 | } |
| 66 | |
| 67 | func (p *Proxy) CheckProxyHTTP(proxy string) { |
| 68 | atomic.AddInt64(&p.openHttpThreads, 1) |
| 69 | defer func() { |
| 70 | atomic.AddInt64(&p.openHttpThreads, -1) |
| 71 | atomic.AddUint64(&checked, 1) |
| 72 | }() |
| 73 | |
| 74 | var err error |
| 75 | var proxyPort = *port |
| 76 | s := strings.Split(proxy, ":") |
| 77 | if len(s) > 1 { |
| 78 | proxyPort, err = strconv.Atoi(strings.TrimSpace(s[1])) |
| 79 | if err != nil { |
| 80 | log.Println(err) |
| 81 | return |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | if len(s) > 1 { |
| 86 | var err error |
| 87 | proxyPort, err = strconv.Atoi(s[1]) |
| 88 | if err != nil { |
| 89 | log.Println(err) |
| 90 | return |
| 91 | } |
| 92 | } |
| 93 | proxyUrl, err := url.Parse(fmt.Sprintf("http://%s:%d", s[0], proxyPort)) |
| 94 | if err != nil { |
| 95 | log.Println(err) |
| 96 | return |
| 97 | } |
| 98 | |
| 99 | tr := &http.Transport{ |
| 100 | Proxy: http.ProxyURL(proxyUrl), |
| 101 | DialContext: (&net.Dialer{ |
| 102 | Timeout: time.Second * time.Duration(config.Timeout.HttpTimeout), |
| 103 | KeepAlive: time.Second, |
| 104 | DualStack: true, |
| 105 | }).DialContext, |
| 106 | } |
| 107 | |
| 108 | client := http.Client{ |
| 109 | Timeout: time.Second * time.Duration(config.Timeout.HttpTimeout), |
| 110 | Transport: tr, |
| 111 | } |
| 112 | |
| 113 | req, err := http.NewRequest("GET", config.CheckSite, nil) |
| 114 | if err != nil { |
| 115 | log.Fatalln(err) |
| 116 | } |
| 117 | req.Header.Add("User-Agent", config.Headers.UserAgent) |
| 118 | req.Header.Add("accept", config.Headers.Accept) |
| 119 | |
| 120 | res, err := client.Do(req) |
| 121 | if err != nil { |
| 122 | atomic.AddUint64(&proxyErr, 1) |
| 123 | if strings.Contains(err.Error(), "timeout") { |
| 124 | atomic.AddUint64(&timeoutErr, 1) |
no test coverage detected