818aa23739
fix(logging,mimeutil,variable): correct data corruption and behavior bugs
...
- logging: pre-allocate fresh slice for request field to avoid mutating
fasthttp internal buffers via append into slices with excess capacity
- mimeutil: move defaultMIME fallback before cache insertion so unknown
extensions are consistently cached as application/octet-stream
- builtin: use -0700 timezone format instead of hardcoded +0800; cache
generated request_id in UserValue to prevent different IDs per expansion
- variable: initialize maps in fallback Context to prevent nil map panic
2026-06-11 16:22:55 +08:00
9824ad5b57
perf(netutil): cache RemoteAddr string formatting
...
Add netutil.FormatRemoteAddr() to avoid repeated net.TCPAddr.String()
allocations on the hot logging path.
- IPv4 addresses use a zero-allocation fast path (custom uint8->ASCII).
- IPv6 falls back to addr.String() with a 1024-entry LRU cache.
- Update logging.LogAccess and variable $remote_addr/$remote_port
getters to use the shared helper.
Eliminates net.JoinHostPort and net.IP.String from top allocators
when access logging is active.
2026-06-11 14:43:12 +08:00
294ff73a7a
test(variable): 添加变量系统覆盖测试(覆盖率 74.5% → 预计 >85%)
...
新建 internal/variable/builtin_coverage_test.go,覆盖低覆盖率函数:
formatRequestTime 测试(原 0%):
- 8 个子测试覆盖零值、毫秒、秒、大值等各种时间格式
SetGlobalVariables 测试(原 0%):
- 正常设置、空配置、覆盖、变量展开
EphemeralGet 测试(原 49.3%):
- 全局变量、回退、server_name、upstream_connect_time
- upstream_header_time、body_bytes_sent、request_time
- UserValue 响应信息、并发安全
GetSSLClientVerify 测试(原 40%):
- TLS UserValue 设置、对端证书存在、无效类型
init 注册验证测试(原 49.3%):
- 验证 16 个内置变量注册
- 验证 5 个 upstream 变量
- 验证 9 个 SSL 变量
- 验证 host/uri/request_uri/args/method 的 GetterBytes 注册
2026-06-04 08:21:48 +08:00
6612819f3a
chore: remove stale AGENTS.md files, rewrite root AGENTS.md
2026-06-03 23:47:29 +08:00
6f17bbad7e
chore: remove trailing blank lines and clean up whitespace
2026-06-03 18:08:34 +08:00
a3b4507be0
refactor: remove unused variable pool statistics dead code
2026-06-03 17:42:48 +08:00
1a6b5f9166
Merge origin/master into master
2026-06-03 16:36:23 +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
xfy911
a136b07bb9
docs: add documentation comments for exported constants and variables
...
- Fix gjson/gjson.go package comments and constant documentation
- Fix internal/config/config.go constant documentation
- Fix internal/utils/httperror.go variable documentation
- Fix internal/matcher/matcher.go constant documentation
- Fix internal/middleware/compression/compression.go constant documentation
- Fix internal/middleware/limitrate/limitrate.go constant documentation
- Fix internal/middleware/rewrite/rewrite.go constant documentation
- Fix internal/middleware/security/access.go and auth.go constant documentation
- Fix internal/ssl/client_verify.go constant documentation
- Fix internal/variable/builtin.go and ssl.go constant documentation
- Fix internal/lua/api_log.go HTTP and log level constant documentation
- Fix internal/benchmark/tools/tools.go constant documentation
- Include author attribution (xfy)
2026-06-03 15:28:53 +08:00
xfy911
396a466de1
docs: add documentation comments for exported constants and variables
...
- Add comments for lua/api_log.go HTTP status codes and log levels
- Add comments for variable/builtin.go and ssl.go constants
- Add comments for utils/httperror.go error variables
- Add comments for matcher/matcher.go location types
- Add comments for compression/compression.go algorithms
- Include author attribution (xfy)
2026-06-03 15:28:53 +08:00
d269940d8b
style: fix formatting issues
...
- Add missing newlines at end of files
- Fix indentation in ssl.go
- Remove extra blank lines
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-30 13:42:53 +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
158964bc6b
test(variable): 变量展开分配追踪测试
...
追踪不同复杂度表达式的分配来源:
- Simple: 1 allocs/op (已达标)
- SingleVar: 1 allocs/op
- NoVar: 0 allocs/op
- ContextPool: 4 allocs/op (池化开销)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-29 10:41:07 +08:00
3d80b12f7d
docs: 为其余模块添加标准化 godoc 注释
...
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 11:23:04 +08:00
2458ac1ed1
docs: 为其余模块添加标准化 godoc 注释
...
为剩余模块添加完整文档注释:
- app: 应用生命周期管理
- cache: 文件缓存
- config: 配置加载器
- handler: 静态文件处理和错误页面
- http2/http3: HTTP/2 和 HTTP/3 适配器
- loadbalance: 负载均衡算法和均衡器
- middleware: bodylimit、compression、rewrite、security
- mimeutil: MIME 类型检测
- netutil: URL 处理工具
- resolver: DNS 解析器
- server: 服务器升级处理
- ssl: SSL/TLS 和 OCSP
- stream: 流处理
- testutil: 测试工具
- variable: 变量池和 SSL 变量
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 10:59:53 +08:00
dc7358bf4e
feat(variable): 添加 EphemeralGet 和 PersistentGet 零拷贝变量访问 API
...
- 新增 EphemeralGet() 方法返回 []byte,用于请求范围内的零拷贝访问
- 新增 PersistentGet() 方法返回 string,用于跨请求持久存储
- BuiltinVariable 结构体添加 GetterBytes 字段支持字节获取器
- Context 结构体添加 bytesCache map 缓存字节值
- 为 $host、$request_uri、$uri、$args、$request_method 添加字节获取器
- 添加完整的单元测试和性能基准测试
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:50:15 +08:00
37d8f9eebc
refactor(variable): 移除废弃的 PoolGet/PoolPut 和别名函数
...
移除 deprecated PoolGet、PoolPut 函数及 NewVariableContext、
ReleaseVariableContext 别名,统一使用 NewContext 和 ReleaseContext。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-15 12:48:49 +08:00
11956a0f83
refactor(resolver,variable): 移除未使用的接口和测试代码
...
- resolver: 移除 StatsCollector 接口和 mockResolver 测试代码
- variable: 移除 Store 接口定义
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 15:56:29 +08:00
a7f01581cb
perf(variable): 全局变量改为惰性加载降低每请求开销
...
之前 NewContext 每次复制所有全局变量到 vc.store,
现在改为 Get() 时按需查找 GetGlobalVariable(),
消除了无关请求的内存复制开销。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 14:25:13 +08:00
1b73df77b6
refactor(variable): 将 PoolStats 的 Mutex 改为 atomic.Int64 计数器
...
使用 sync/atomic 替代 sync.RWMutex,消除统计操作中的锁开销,
提升并发性能。保持 PoolStats 公开 API 不变(返回 plain int64)。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 14:24:52 +08:00
d21e27fbac
fix(lint): 修复 golangci-lint 错误 (119 -> 0 issues)
...
主要修复:
- errcheck: defer Close 使用 //nolint:errcheck,类型断言改为 ok 检查
- govet fieldalignment: 调整结构体字段顺序优化内存布局
- revive unused-parameter: 将未使用参数改为 _
- exhaustive: 添加缺失的 switch case 或 default
- goconst: 提取重复字符串为常量 (accessAllow, accessDeny 等)
- staticcheck SA9003: 修复空分支逻辑
- gofmt: 运行 gofmt -w 格式化
- nolintlint: 修复 nolint 注释格式
其他改进:
- 更新 .golangci.yml 配置,启用更严格的检查
- 移除未使用的代码和导入
- 简化测试辅助函数调用
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 16:15:31 +08:00
95b6119e34
refactor: 使用标准库 slices/maps 替代自定义函数
...
- 使用 slices.Contains 替代 contains/containsInt 函数
- 使用 maps.Copy 替代手动遍历复制
- 删除 internal/cache 中不再需要的辅助函数
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 13:15:13 +08:00
20518495b3
refactor: 删除未使用的辅助函数
...
移除两个保留但实际未调用的函数:
- proxy: 删除 handleWebSocket(WebSocket逻辑已整合到 ServeHTTP)
- variable/ssl: 删除 parsePEMCertificate(证书解析已在其他模块处理)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 11:38:12 +08:00
e9d747a628
refactor(variable): 提取变量展开核心逻辑
...
提取 expandCore 函数作为变量展开的核心实现,
消除 Expand 和 ExpandString 方法中的重复代码。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 10:59:07 +08:00
8b382606df
Merge branch 'lint-fix' - resolve sendfile.go conflict
...
Conflict: sendfile.go (!linux build tag) was incorrectly modified to
include linuxSendfile and getSocketFd functions which already exist
in sendfile_linux.go.
Resolution: Keep HEAD version (simple fallback returning ENOTSUP) as
Linux implementation is properly separated in sendfile_linux.go.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 09:26:48 +08:00
eb379d9121
test(proxy,ssl,server,variable): 补全测试覆盖
...
- websocket: 升级请求构建、响应读写、大消息转发、并发桥接
- ssl: CRL 吊销检查、证书链深度限制、完整验证流程
- server: 初始化配置、静态文件、GoroutinePool、FileCache
- variable: mTLS 客户端证书变量和指纹计算
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 17:59:22 +08:00
edf192ff85
docs(proxy,resolver,variable): 增强公开 API 文档注释
...
- proxy: 添加 upstreamCache/protoHTTPS 常量说明
- proxy_dns: 添加文件级文档和所有公开方法的详细注释
- stats: 增强 StatsCollector 接口文档和方法注释
- pool: 增强 PoolStats 字段注释和公开函数文档
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 15:29:21 +08:00
4a93cf2b5c
refactor(variable): 简化变量池函数
...
- PoolGet() 改为调用 NewContext()
- PoolPut() 改为调用 ReleaseContext()
- 添加 Deprecated 文档注释
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 11:20:50 +08:00
53319bbdd3
docs(variable): 更新 AGENTS.md 反映类型重命名
...
VariableContext → Context 相关文档同步更新
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:26 +08:00
0731dc46e4
refactor(variable): 重命名核心类型移除冗余前缀
...
VariableContext → Context
VariableStore → Store
ReleaseVariableContext → ReleaseContext (别名保留向后兼容)
提取硬编码字符串为命名常量 sslProtocolNone
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:17 +08:00
392d0b3449
docs: 新增模块 AGENTS.md 文档,更新目录索引
...
- 新增 http2、integration、resolver、variable 模块 AGENTS.md
- 更新 internal/AGENTS.md 目录表,补充新模块条目
- 更新 docs/prompts.md 添加 generate-config 缺失项分析提示
- 同步更新日期戳至 2026-04-09
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 13:35:29 +08:00
4d5dda5b69
style(variable): 添加文件末尾换行符
2026-04-09 12:19:22 +08:00
668ecde6db
feat(variable): 新增全局变量支持,自动注入请求上下文
2026-04-09 12:18:56 +08:00
25bdba4e01
test(benchmark): 新增组件级基准测试套件
...
- 新增 benchmark_context.go 标准化测试上下文构造器
- 新增静态文件处理器基准测试(缓存命中/未命中、try_files)
- 新增访问日志中间件基准测试
- 新增压缩中间件基准测试(gzip/brotli、Pool 复用)
- 新增限流器基准测试(令牌桶、滑动窗口、多客户端并发)
- 新增变量展开基准测试(模板展开、Pool 操作)
2026-04-08 18:25:38 +08:00
b7de258f4e
feat(variable): 新增 SSL 客户端证书变量支持
...
- 新增 ssl_client_verify、ssl_client_serial、ssl_client_subject 等变量
- 支持从 TLS 连接状态提取客户端证书信息
- 用于日志记录和访问控制决策
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-08 14:36:53 +08:00
61455412eb
feat(variable,proxy): 新增上游变量支持,集成到代理请求处理
...
- 新增 upstream_addr、upstream_status、upstream_response_time 等变量
- 新增 UpstreamTiming 结构体捕获连接、首字节、响应时间
- Proxy.ServeHTTP 集成变量上下文,记录上游时间
- 新增测试覆盖上游变量和计时功能
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-08 14:36:37 +08:00
c95f474539
feat(variable): 新增变量系统支持
...
新增 internal/variable 包,提供 Nginx 风格的变量展开功能:
- 支持 $remote_addr、$host、$uri、$args 等 30+ 内置变量
- 使用 sync.Pool 优化 VariableContext 分配
- 支持 set_response_info 存储响应状态信息
添加 github.com/google/uuid 依赖用于请求 ID 生成。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-08 11:36:49 +08:00