fix(libhttp,dnfs2): HttpClient 新增超时接口,dnfs2 启用配置超时

修复 dnfs2 审计 L-3(P2-N5):

libhttp HttpClient 硬编码 CURLOPT_TIMEOUT=30L/CONNECTTIMEOUT=10L,
dnfs2 的 gateway_timeout/review_timeout 配置加载后从未使用,实际超时恒为 30s。

修复:
- libhttp HttpClient 新增 set_timeout/set_connect_timeout 接口
  (默认 30s/10s,向后兼容 gateway/core)
- request_stream_sync 使用成员变量替代硬编码值
- dnfs2 decode_token 设置 gateway_timeout
- dnfs2 review_content 设置 review_timeout

安全评级 A- → A,已知限制 6→5 项。
This commit is contained in:
qing committed 2026-08-08 01:33:57 +08:00
1 parent 9804838e96
commit 117fc0241e
5 files changed
+70 -16

No files matched your search

+10
View File
@@ -65,6 +65,14 @@ public:
void set_max_response_size(size_t bytes);
size_t get_max_response_size() const;
// ===== 请求超时控制 =====
// 设置整体请求超时(秒,含连接+传输)。默认 30s。
void set_timeout(long seconds);
long get_timeout() const;
// 设置连接建立超时(秒)。默认 10s。
void set_connect_timeout(long seconds);
long get_connect_timeout() const;
// ===== WebSocket Methods (Synchronous, Boost.Beast-based) =====
bool ws_connect(const std::string& url, int timeout_ms = 5000);
bool ws_connect(const std::string& host, const std::string& port,
@@ -84,6 +92,8 @@ private:
std::map<std::string, std::string> response_headers_;
long response_code_ = 0;
size_t max_response_size_ = 10 * 1024 * 1024; // 默认 10MB,对齐 WAF;0 表示不限制
long timeout_ = 30; // 整体请求超时(秒),默认 30s
long connect_timeout_ = 10; // 连接建立超时(秒),默认 10s
struct WsState {
asio::io_context ioc;
+18 -2
View File
@@ -42,6 +42,22 @@ size_t HttpClient::get_max_response_size() const {
return max_response_size_;
}
void HttpClient::set_timeout(long seconds) {
timeout_ = seconds;
}
long HttpClient::get_timeout() const {
return timeout_;
}
void HttpClient::set_connect_timeout(long seconds) {
connect_timeout_ = seconds;
}
long HttpClient::get_connect_timeout() const {
return connect_timeout_;
}
void HttpClient::set_header(const std::string& header) {
headers_ = curl_slist_append(headers_, header.c_str());
}
@@ -89,8 +105,8 @@ void HttpClient::request_stream_sync(
curl_easy_setopt(curl_, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl_, CURLOPT_WRITEDATA, &write_ctx);
curl_easy_setopt(curl_, CURLOPT_TIMEOUT, 30L);
curl_easy_setopt(curl_, CURLOPT_CONNECTTIMEOUT, 10L);
curl_easy_setopt(curl_, CURLOPT_TIMEOUT, timeout_);
curl_easy_setopt(curl_, CURLOPT_CONNECTTIMEOUT, connect_timeout_);
CURLcode res = curl_easy_perform(curl_);