InitHTTPClient 创建HTTP客户端
(ThreadsNum int, DownProxy string, Timeout time.Duration, maxRedirects int, networkConfig *common.NetworkConfig)
| 124 | |
| 125 | // InitHTTPClient 创建HTTP客户端 |
| 126 | func InitHTTPClient(ThreadsNum int, DownProxy string, Timeout time.Duration, maxRedirects int, networkConfig *common.NetworkConfig) error { |
| 127 | // 配置基础连接参数 |
| 128 | dialer := &net.Dialer{ |
| 129 | Timeout: dialTimeout, |
| 130 | KeepAlive: keepAlive, |
| 131 | } |
| 132 | |
| 133 | // 配置Transport参数 |
| 134 | tr := &http.Transport{ |
| 135 | DialContext: dialer.DialContext, |
| 136 | MaxConnsPerHost: 100, // 增加到100,避免连接池耗尽 |
| 137 | MaxIdleConns: 100, // 保留100个空闲连接 |
| 138 | MaxIdleConnsPerHost: 10, // 每主机保留10个空闲连接 |
| 139 | IdleConnTimeout: keepAlive, |
| 140 | TLSClientConfig: &tls.Config{MinVersion: tls.VersionTLS10, InsecureSkipVerify: true}, |
| 141 | TLSHandshakeTimeout: 5 * time.Second, |
| 142 | DisableKeepAlives: false, |
| 143 | } |
| 144 | |
| 145 | // 统一配置代理 |
| 146 | if err := configureHTTPProxy(tr, DownProxy, networkConfig); err != nil { |
| 147 | return err |
| 148 | } |
| 149 | |
| 150 | // 创建标准HTTP客户端(限制重定向次数) |
| 151 | Client = &http.Client{ |
| 152 | Transport: tr, |
| 153 | Timeout: Timeout, |
| 154 | CheckRedirect: func(req *http.Request, via []*http.Request) error { |
| 155 | if len(via) >= maxRedirects { |
| 156 | return http.ErrUseLastResponse // 达到限制,使用最后响应 |
| 157 | } |
| 158 | return nil // 继续跟随 |
| 159 | }, |
| 160 | } |
| 161 | |
| 162 | // 创建不跟随重定向的HTTP客户端 |
| 163 | ClientNoRedirect = &http.Client{ |
| 164 | Transport: tr, |
| 165 | Timeout: Timeout, |
| 166 | CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse }, |
| 167 | } |
| 168 | |
| 169 | return nil |
| 170 | } |
| 171 | |
| 172 | // Poc 定义漏洞检测配置结构 |
| 173 | type Poc struct { |
no test coverage detected