SafeHTTPDo 带发包控制的HTTP请求
(client *http.Client, req *http.Request)
| 163 | |
| 164 | // SafeHTTPDo 带发包控制的HTTP请求 |
| 165 | func SafeHTTPDo(client *http.Client, req *http.Request) (*http.Response, error) { |
| 166 | // 检查发包限制 |
| 167 | if canSend, reason := CanSendPacket(); !canSend { |
| 168 | LogError(fmt.Sprintf("HTTP请求 %s 受限: %s", req.URL.String(), reason)) |
| 169 | return nil, fmt.Errorf("发包受限: %s", reason) |
| 170 | } |
| 171 | |
| 172 | // 执行HTTP请求 |
| 173 | resp, err := client.Do(req) |
| 174 | |
| 175 | // 统计TCP包数量 (HTTP本质上是TCP) |
| 176 | if err != nil { |
| 177 | GetGlobalState().IncrementTCPFailedPacketCount() |
| 178 | } else { |
| 179 | GetGlobalState().IncrementTCPSuccessPacketCount() |
| 180 | } |
| 181 | |
| 182 | return resp, err |
| 183 | } |
no test coverage detected