d6ee721bc8
test(adapter): 为 adapter 包添加完整单元测试(覆盖率 0% → 预计 >80%)
...
添加 internal/adapter/common_test.go,覆盖 CommonAdapter 的所有公开方法:
- TestDefaultBodyThreshold: 验证 DefaultBodyThreshold 常量值
- TestNewCommonAdapter: 验证构造函数返回非空实例及 CtxPool 初始化
- TestResetContext: 验证请求/响应/用户值状态重置
- TestResetContext_DisableNormalizing: 验证头部规范化禁用
- TestStreamRequestBody: 表驱动测试覆盖 nil body、NoBody、空体、
小体(≤64KB)、阈值体、大体(>64KB)、未知长度
- TestStreamRequestBody_ReadError: 读取错误不 panic
- TestStreamRequestBody_PartialReadError: 部分读取错误时保留已读数据
- TestGetContext/PutContext: Pool 获取/归还正确性
- TestGetContext_PutAndGet: 完整的 get-put-get 循环
- TestConcurrentPoolAccess: 100 goroutine 并发安全
- TestConcurrentStreamRequestBody: 50 goroutine 并发流式读取
2026-06-04 08:13:25 +08:00
2734b04d8f
refactor: remove 16.8k lines of dead code across all internal packages
...
- Delete unused files: tempfile subsystem, matcher variants, server/internal
- Remove 200+ unused functions across proxy, ssl, lua, http2/3, stream, variable
- Fix proxy test type errors (backgroundRefresh ctx→Request)
- Move bench/tools mock backend into internal/testutil
- Remove corresponding test functions for all deleted code
2026-06-03 16:15:43 +08:00
f145a8770e
refactor: modernize code with Go 1.22+ features
...
Apply modern Go patterns across the codebase:
- Replace `interface{}` with `any` (Go 1.18+)
- Use `for range n` instead of `for i := 0; i < n; i++` (Go 1.22+)
- Replace `sort.Slice` with `slices.Sort` from slices package
- Simplify sync.WaitGroup patterns with errgroup where appropriate
- Add Makefile targets for modernize analyzer
Total: 84 files updated, net reduction of 79 lines
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-30 10:37:45 +08:00
11e22c80b8
perf: 零分配优化与 Dial timeout 支持
...
- 添加 b2s/s2b 零分配字节-字符串转换工具函数
- WebSocket 数据转发使用 sync.Pool 复用 32KB buffer
- 条件化 Debug 日志避免非 Debug 级别的字符串分配
- 缓存键哈希计算直接写入 []byte 避免 string 转换
- 使用 bytes.EqualFold 替代 strings.ToLower 进行大小写不敏感比较
- generateETag 使用 strconv.AppendInt 避免 fmt.Sprintf
- 支持 Dial timeout 配置,区分 TCP 连接建立和总连接超时
- MaxConnsPerHost 默认值改为 512(fasthttp 推荐)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-28 20:11:20 +08:00
6f6a8f0455
refactor(adapter): 提取 HTTP/2/3 适配器公共逻辑为 CommonAdapter
...
将 http2 和 http3 适配器中重复的 sync.Pool 管理、流式请求体处理、
上下文重置等逻辑提取到 internal/adapter 包,通过 struct embedding 复用。
同时简化 ConnLimiter 直接实现 middleware.Middleware 接口,移除冗余 wrapper。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-28 17:06:41 +08:00