Repository navigation
refactor(config): 删掉 14 个从未被读取的配置字段与 4 个假旋钮 API - #472
Merged
Merged
Conversation
v2.10 roadmap d2(配置静默失效全线)。核实结论:`uvhttp_config_t` 原 26 个 字段中 14 个从不被任何执行路径读取 —— 它们被 set_defaults 填默认值、被 validate 校验范围、被 print 打印,然后被整个库忽略。 三个公共 API 报告成功、打 INFO 日志,对服务器行为零影响: - uvhttp_config_update_size_limits:写 max_body_size/max_header_size 后打 "Limits updated - Body: %zu -> %zu" - uvhttp_set_max_body_size(builder):写 max_body_size,返回 builder - uvhttp_set_timeout(builder):写 request_timeout/keepalive_timeout - uvhttp_config_update_read_buffer_size:写 read_buffer_size 这些字段的真实权威(逐个核实): - read_buffer_size → 编译期 UVHTTP_READ_BUFFER_SIZE(connection.c:647) - max_body_size → 编译期 UVHTTP_MAX_BODY_SIZE(request.c:308 等 4 处) - max_url_size → MAX_URL_LEN 2048(request.h:60) - max_header_size → 无任何实现 - max_requests_per_connection → 无任何实现(keep-alive 无上限) - request_timeout / keepalive_timeout → config->connection_timeout (connection.c:1551-1553,二者是同一裁决者的两个别名) - rate_limit_* 四项 → server->rate_limit_*(uvhttp_server_enable_rate_limit) - cache_default_max_entries / cache_default_ttl → 编译期常量 - lru_cache_batch_eviction_size → 编译期常量 取舍:删而非接。max_body_size 看似一条线就能接上,但 request body、 response body、compress 阈值三条路径各自独立,接一个留三个就是"两套权威" —— 正是本轮要治的病。需要可调时,把字段与读取它的代码一起加回来。 改动面: - uvhttp_config_t 26 → 12 字段,validate/print/set_defaults 同步收敛 - 4 个假旋钮 API 删除,头文件补"字段要么权威要么不存在"的规则说明 - 11 个测试用例组(validate 边界 / update API / 全字段用例)随 API 消失 - ConfigSetDefaultsValid 强化为钉住**存活** 12 个字段的默认值 —— 它是那份 清单的守门人:字段增减必须与"谁读它"同步 - 6 个示例改为只演示真实生效的字段(原先 helloworld/config_demo 把死字段 当卖点演示并打印) - docs/spec/config-api.md 重写:列出 14 字段的"真实权威归属表" + 存活 12 字段的真实默认值/范围(该表改动前就已失真:列了结构体里根本不存在的 max_headers / tcp_nodelay / tcp_keepalive) - 中英文档 10 处配置示例同步(FAQ / performance / introduction / TUTORIAL 参数表 / PERFORMANCE_TESTING_STANDARD) 顺带修一个既有 ASan 泄漏(与本次配置改动无关,但会卡住 ASan release 门禁): test_server_simple_handlers_coverage 的 GetHeader 用例在 #455 改成用 uvhttp_request_add_header 构造可查询 header 后,没有释放它堆分配的 headers_extra —— request 本身在栈上,不会有人替你调析构。main 上即复现。 验证:ctest 120/120(含 ASan 全量);cppcheck(CI 同参数)零告警; test-validity 门禁 PASS(零断言测试新增 0);examples 全量构建通过; 本 PR 触达的 src/include/test 文件 clang-format 18.1.8 全合规(release 门禁口径)。
adam-ikari
force-pushed
the
refactor/config-dead-fields
branch
from
October 11, 2026 04:23
68fb2a7 to
0ab35f8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
uvhttp_config_t原 26 个字段中,14 个从不被任何执行路径读取 —— 它们被set_defaults填默认值、被validate校验范围、被print打印,然后被整个库忽略。三个公共 API 因此报告成功、打 INFO 日志、返回 OK,而对服务器行为零影响:
uvhttp_config_update_size_limits—— 写完max_body_size/max_header_size后打Limits updated - Body: %zu -> %zuuvhttp_set_timeout(builder)—— 写request_timeout/keepalive_timeoutuvhttp_set_max_body_size(builder)—— 写max_body_sizeuvhttp_config_update_read_buffer_size—— 写read_buffer_size与 [[api-atomization-orthogonalization]] 记录的结论一致:这不是"配置可能失效",是必然失效且静默。
14 个字段的真实权威(逐字段核实)
read_buffer_sizeUVHTTP_READ_BUFFER_SIZE(connection.c:647)max_body_sizeUVHTTP_MAX_BODY_SIZE(request.c:308 / response.c:462,1170 / utils.c:79)max_url_sizeMAX_URL_LEN2048(request.h:60)max_header_sizemax_requests_per_connectionrequest_timeout/keepalive_timeoutconfig->connection_timeout(connection.c:1551-1553,二者是同一裁决者的两个别名)rate_limit_window/_max_requests/_max_window_seconds/_min_timeout_secondsserver->rate_limit_*(uvhttp_server_enable_rate_limit)cache_default_max_entries/cache_default_ttllru_cache_batch_eviction_size决策:删,而不是接上执行点
max_body_size这类看起来"一条线就能接上",但 request body、response body、compress 阈值三条路径各自独立 —— 接一个留三个就是两套权威,正是本轮要治的病。需要可调时,把字段与读取它的代码一起加回来。改动面
uvhttp_config_t26 → 12 字段,set_defaults/validate/print同步收敛ConfigSetDefaultsValid强化为钉住存活 12 个字段的默认值 —— 它是清单守门人(变异验证:删掉任一默认值赋值 → 该用例变红)docs/spec/config-api.md重写:14 字段"真实权威归属表" + 存活 12 字段的真实默认值/范围。该表改动前已失真:列了结构体里根本不存在的max_headers/tcp_nodelay/tcp_keepalive验证
ConfigSetDefaultsValid红迁移
request_timeout/keepalive_timeout的 → 改设connection_timeout(5-300 秒)max_body_size/read_buffer_size/max_url_size的 → 改为编译期常量(uvhttp_constants.h)或自行在应用层限流rate_limit_*的 → 改走uvhttp_server_enable_rate_limit()uvhttp_config_set_cache_config(shared)经uvhttp_static_set_cache_config的用法不变