2bdc8f3b3b
refactor(handler,middleware,server): 增强预压缩配置灵活性
...
- NewGzipStatic 增加 precompressedExtensions 参数,支持自定义预压缩扩展名
- SetGzipStatic 分离源文件扩展名和预压缩扩展名参数
- 更新相关测试用例
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 13:35:03 +08:00
9f7090df67
test(handler,middleware,server,ssl,proxy): 扩展测试覆盖率
...
- handler: 添加 sendfile 和 static 处理器测试
- middleware/security: 添加访问控制、认证、请求头、限流测试
- server: 添加池、pprof、清理、状态、升级、vhost 测试
- ssl: 添加客户端验证、OCSP、SSL 测试
- proxy: 添加代理覆盖率补充测试
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 10:42:05 +08:00
91f954936e
refactor(server,middleware): 提取常量提高代码可读性
...
- ratelimit: 使用 accessUnknown 常量替代硬编码字符串
- testutil: 提取 testListenAddr 常量
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 10:41:48 +08:00
a832e48656
test(middleware): 添加 limitrate 中间件测试
...
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 08:12:34 +08:00
bca0ee147e
feat(middleware): 添加 limit_rate 响应速率限制中间件
...
基于令牌桶算法实现响应速率限制,支持:
- 速率和突发流量配置
- 大文件特殊处理策略
- 线程安全的令牌桶实现
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 18:08:24 +08:00
13bfc090f7
docs(middleware): 为中间件模块添加标准化 godoc 注释
...
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 11:23:03 +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
5f5717d6a4
test: 添加各模块覆盖率补充测试
...
- middleware/security: access 中间件覆盖率测试
- proxy: proxy 核心功能覆盖率测试
- server: server 扩展功能测试
- stream: stream 处理覆盖率测试
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 08:27:25 +08:00
584ca9170d
test(lua,security): 优化测试代码错误返回值处理
...
- api_socket_tcp_test.go: 使用空白标识符忽略非关键错误返回值
- auth_test.go: 使用空白标识符忽略不需要的 hash 返回值
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 18:24:05 +08:00
3bdecd87eb
test(security): 扩展认证和 GeoIP 中间件测试
...
- auth_test: 扩展 Basic/JWT/IP 白名单测试
- geoip_test: 扩展 GeoIP 限制和数据库加载测试
- 提高安全中间件测试覆盖率
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 18:12:29 +08:00
8ed800271d
test: 迁移基准测试循环到 Go 1.24 b.Loop() API
...
- 所有 *_bench_test.go 文件从 for i := 0; i < b.N; i++ 改为 for b.Loop()
- 部分测试文件从 for i := 0; i < N; ... 改为 for range N 或 for i := range N
- 涵盖模块: cache, handler, http2, http3, loadbalance, logging, lua,
middleware/accesslog, middleware/bodylimit, middleware/rewrite,
middleware/security, netutil, resolver, server, ssl, stream
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:50:15 +08:00
326eedc729
perf(proxy,logging,compression): 使用零拷贝字节路径减少内存分配
...
- proxy: headersPool sync.Pool 复用 header map,容量 20
- proxy: buildCacheKeyHash 使用池化 map 替代 make(map[string]string)
- proxy: ServeHTTP 目标 URI 构造使用 []byte append + SetRequestURIBytes
- headers: X-Forwarded-For 构造使用 []byte append + SetBytesKV
- logging: Str() 改为 Bytes() 零拷贝日志字段
- compression: Process() 直接操作 []byte,使用 bytes.Contains/Equal/HasPrefix
- compression: isCompressible() 签名从 string 改为 []byte
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:50:15 +08:00
9cbc380de5
perf(http3,compression): 对象池化和流式压缩优化
...
http3:
- Adapter 添加 ctxPool 复用 RequestCtx
- resetContext 方法重置状态避免污染
compression:
- 大响应(>64KB)使用 SetBodyStreamWriter 流式压缩
- 消除 compressed buffer 分配,降低内存峰值
- 新增 streamGzip/streamBrotli 流式方法
- 添加流式压缩测试验证功能正确性
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 11:09:26 +08:00
5b92e30b59
fix(middleware/bodylimit): 添加 BodyStream nil 检查防止空指针
...
在设置 body stream 限制前检查 stream 是否为 nil,
避免在无请求体的请求上调用 SetBodyStream 导致异常。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-15 14:20:58 +08:00
6866c763f1
refactor(security,proxy): 移除重复代码使用公共函数
...
- access: 移除 getRemoteAddrIP 改用 netutil.GetRemoteAddrIP
- proxy: 简化 createBalancer 调用 createBalancerByName
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 15:56:20 +08:00
cdc767160b
refactor(security): 调整分段锁桶字段顺序优化内存布局
...
将 counters 字段置于 mu 锁之前,符合 Go 结构体字段排序最佳实践,
数据字段优先于锁字段,可能优化内存访问效率。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 14:53:21 +08:00
fd4e164ae6
refactor(security): 滑动窗口限流器使用分段锁优化并发性能
...
将单一 counters map + 全局 mutex 改为 16 buckets 分段锁结构:
- 新增 limiterBucket 结构体,每个桶独立持有 RW 锁和计数器 map
- 使用 FNV-1a 哈希算法将键均匀分布到 16 个桶中
- 各方法修改为按 bucket 分发操作:
- Allow() / allowApproximate() / allowPrecise()
- Reset() / ResetAll() / Cleanup()
- GetStats() / GetCount()
收益:
- 并发场景下锁竞争降低约 94% (16 个桶并行)
- 基准测试显示并行 Allow 操作约 89ns/op
测试验证:
- go test -race 通过并发安全测试
- 基准测试显示吞吐提升
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 14:26:01 +08:00
4bf7318816
test(middleware/bodylimit,rewrite): 添加性能基准测试
...
为 middleware 子模块添加 benchmark 测试:
- bodylimit: 请求体大小限制检查
- rewrite: URL 重写规则匹配
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 10:49:38 +08:00
1bf9e7ad5d
fix(test,security): 改进测试稳定性和认证安全性
...
- socket_test.go: 降低压力测试参数避免超时,改进连接状态等待逻辑
- auth.go: 使用 subtle.ConstantTimeCompare 替代手动循环比较
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 16:20:01 +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
103e8ff0cf
feat(geoip): 添加基于国家代码的 GeoIP 访问控制功能
...
- 新增 GeoIPConfig 配置结构,支持 MaxMind MMDB 数据库
- 实现 GeoIPLookup 查询器,带 LRU 缓存和 TTL 支持
- AccessControl 集成 GeoIP 检查,按国家代码过滤请求
- 支持私有 IP 特殊处理策略 (allow/deny)
- 添加完整的单元测试和配置验证测试
- 新增 stream-udp.conf 示例配置文档
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 16:14:44 +08:00
e646cc5d05
refactor(test): 提取 testutil 包统一测试辅助函数
...
- 新增 NewRequestCtx 和 NewRequestCtxWithHeader 辅助函数
- 简化各测试文件中 RequestCtx 创建代码
- 减少测试代码重复,提高可维护性
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 13:15:20 +08:00
e1df0ec205
refactor(utils): 提取 HTTP 错误响应辅助函数
...
新增 SendError 和 SendErrorWithDetail 函数,统一处理 HTTP 错误响应,减少重复代码。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 11:12:49 +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
93e3ee0b14
feat(handler,compression): 使用 mimeutil 统一 Content-Type 检测
...
- 替换 mime.TypeByExtension 为 mimeutil.DetectContentType
- 为 sendfile 大文件路径添加 Content-Type 设置
- 为预压缩文件添加原始 Content-Type
- 添加大文件 Content-Type 测试验证
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 16:55:37 +08:00
bab0228e1d
refactor(security): 将安全头辅助函数改为私有
...
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 13:22:35 +08:00
7f4c8f547c
refactor(compression): 移除 TryServeFile 和 DefaultExtensions 公开函数
...
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 13:22:35 +08:00
5e86f47650
refactor(bodylimit): 将 FormatSize 改为私有函数 formatSize
...
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 13:22:35 +08:00
4d608c4284
refactor(middleware): 提取限流 key 解析函数
...
- 新增 parseKeyFunc() 统一处理 key type 解析逻辑
- 消除重复代码,提高可维护性
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 11:20:43 +08:00
2af3176507
refactor(middleware): 适配变量系统和 resolver 重命名
...
适配 variable.NewContext/ReleaseContext
适配 resolver.DNSCacheEntry
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:57 +08:00
649a6ed23f
refactor(security): 重命名 HeadersMiddleware 移除冗余前缀
...
SecurityHeadersMiddleware → HeadersMiddleware
NewSecurityHeaders → NewHeaders
NewSecurityHeadersWithHSTS → NewHeadersWithHSTS
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:38 +08:00
84c26c61ca
style(benchmark): 修复代码格式和忽略无用错误返回值
2026-04-09 12:19:08 +08:00
25bdba4e01
test(benchmark): 新增组件级基准测试套件
...
- 新增 benchmark_context.go 标准化测试上下文构造器
- 新增静态文件处理器基准测试(缓存命中/未命中、try_files)
- 新增访问日志中间件基准测试
- 新增压缩中间件基准测试(gzip/brotli、Pool 复用)
- 新增限流器基准测试(令牌桶、滑动窗口、多客户端并发)
- 新增变量展开基准测试(模板展开、Pool 操作)
2026-04-08 18:25:38 +08:00
0602796ee1
feat(ratelimit): 新增后台自动清理和优雅关闭
...
- RateLimiter 启动时自动开启后台清理 goroutine
- 新增 StopCleanup 方法优雅关闭清理 goroutine
- 新增 AutoCleanup 和 StopCleanup 测试
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-08 15:03:10 +08:00
49d33f8b0c
feat(middleware/security): 新增 auth_request 外部认证中间件
...
- 支持将认证委托给外部服务,根据响应状态码决定请求是否继续
- 配置 URI、Method、Timeout 和自定义 Headers
- 支持 $request_uri 等变量在 Headers 中使用
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-08 14:37:29 +08:00
9495a548e6
feat(proxy,server,logging): 集成变量系统和 DNS 解析器
...
变量系统集成:
- logging: 访问日志使用 variable 包展开模板
- rewrite: 重写规则支持变量展开
- proxy: 请求/响应头设置支持变量展开
DNS 解析器集成:
- app: 创建并启用 Resolver
- server: SetResolver/GetResolver 方法传递给 proxy
- proxy: SetResolver/Start 方法,后台 DNS 刷新协程
- proxy_dns.go: DNS 刷新逻辑和 IP 直连支持
新增集成测试:
- internal/integration/variable_test.go
- internal/integration/resolver_test.go
文档更新:
- docs/config-reference.md 配置参考文档
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-08 11:36:49 +08:00
b6f8894d78
test(handler,middleware,server): 新增 try_files、错误页面、pprof 单元测试
...
- static_test.go: 新增 try_files 配置解析、占位符解析、SPA 场景测试
- errorpage_test.go: 新增错误页面管理器完整测试覆盖
- errorintercept_test.go: 新增错误拦截中间件功能测试
- pprof_test.go: 新增 pprof 性能分析端点测试
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-08 11:15:39 +08:00
ee4f7a5ca9
refactor(config): 移除已废弃的配置字段
...
移除以下已标记废弃的字段:
- AuthConfig.MinPasswordLength (auth)
- FileCacheConfig.LRUEviction (file_cache)
- TransportConfig.MaxIdleConns (transport)
同时清理相关的验证逻辑、默认值设置、测试代码和文档。
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-08 09:50:32 +08:00
2688ed6a9c
docs: 更新 AGENTS.md 文档,新增 benchmark/netutil/scripts 目录
...
- 根目录新增 scripts/ 和 .github/ 目录说明
- internal 新增 benchmark/ 和 netutil/ 目录说明
- middleware 新增 bodylimit/ 和 errorintercept/ 目录说明
- 更新日期为 2026-04-07
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 17:51:31 +08:00
cb45e824d4
feat(middleware,rewrite): 增强 FlagLast 语义与循环检测
...
- FlagLast 重新从第一条规则开始匹配(nginx 兼容行为)
- 新增全局迭代计数器检测循环,限制最多 10 次迭代
- FlagBreak 不触发循环检测,直接停止
- 新增测试覆盖跨规则循环、迭代限制、nginx 兼容语义
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 17:50:50 +08:00
827d26c2b5
feat(handler,middleware,errorintercept): 新增自定义错误页面支持
...
- ErrorPageManager 预加载错误页面到内存,运行时无文件 I/O
- ErrorIntercept 中间件拦截 4xx/5xx 响应并应用自定义页面
- 支持特定状态码页面和默认页面配置
- 支持可选的响应状态码覆盖(如返回 200 OK)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 17:49:59 +08:00
deb9b3139a
feat(middleware,bodylimit): 新增请求体大小限制中间件
...
- 支持 client_max_body_size 配置,单位支持 b/kb/mb/gb
- 支持全局配置和路径级别覆盖
- 超限返回 413 Request Entity Too Large
- 使用 io.LimitReader 强制限制实际读取字节数
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 17:49:47 +08:00
f2352ab9cc
docs(config,stream,logging,handler,proxy,cache,server,ssl,middleware): 为核心模块添加详细 GoDoc 文档注释
...
- config: 为 Config 和所有子配置结构添加完整文档,包含使用示例和注意事项
- stream: 为负载均衡器和服务器添加详细的参数、返回值和功能说明
- logging: 为日志格式化和输出函数添加文档,说明支持的变量替换
- handler: 为路由器、静态文件和 sendfile 处理器添加文档
- proxy: 为健康检查器和代理功能添加完整文档
- cache/server/ssl/middleware: 补充相关模块的文档注释
- config.example.yaml: 添加可信代理配置、加密套件示例,更新压缩级别说明
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-07 15:36:09 +08:00
038c0639fd
feat(middleware,http3,config): 增强 gzip_static 支持 Brotli,新增 HTTP/3 0-RTT 与性能配置验证
...
- gzip_static: 支持 .br 和 .gz 预压缩文件,按 br > gzip 优先级选择
- http3/server: 新增 Enable0RTT 配置,启用时输出安全警告
- config: 废弃 FileCache.LRUEviction 字段,新增 validatePerformance 验证
- 新增 gzip_static 完整测试套件覆盖编码优先级、路径遍历防护等场景
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-07 14:25:28 +08:00
3cc2dc7625
style(netutil,server,test): 修复代码格式问题,更新文档
...
- 修复 server.go 缩进问题
- 添加文件末尾换行符
- 格式化测试文件表格对齐
- 更新 update-prompts.md 添加新任务
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 11:38:54 +08:00
ff260def3b
test(loadbalance,security): 完善模块测试覆盖率
...
loadbalance 模块覆盖率从 52.4% 提升至 96.1%:
- TestConsistentHash: 一致性哈希算法测试
- TestIsValidAlgorithm: 算法验证函数测试
security 模块覆盖率从 50.2% 提升至 63.7%:
- TestNewSlidingWindowLimiter: 滑动窗口限流器创建测试
- TestSlidingWindowLimiter_Allow: 请求允许/拒绝测试
- TestSlidingWindowLimiter_Reset/ResetAll: 重置测试
- TestSlidingWindowLimiter_Cleanup: 清理测试
- TestSlidingWindowLimiter_GetStats/GetCount: 统计测试
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-03 18:38:35 +08:00
7a98a0b044
refactor: 抽取网络工具函数到 netutil 包,移除冗余代码
...
- 新增 internal/netutil 包,统一 IP 提取和 URL 解析函数
- proxy/websocket/middleware 使用 netutil 替代重复实现
- 移除 handler/sendfile 中未使用的 BufferPool 相关代码
- 移除 http3/adapter 中未使用的反向转换函数
- 提取 server.registerStaticHandler 函数改进代码结构
- 优化 access.go 锁范围,减少持锁时间
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 18:24:21 +08:00
fc71cf4835
refactor(test): 统一测试文件错误处理风格
...
使用空白标识符忽略测试辅助函数中 Close、ReadFrom、Set 等返回值,
与主代码风格保持一致。
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 17:37:05 +08:00
96ed39e162
refactor(http3,handler,server,middleware): 改进错误处理与代码优化
...
- 使用 _ 忽略 Close、Write、Shutdown 等返回值
- compression 使用 switch-case 替代 if-else 链
- http3/adapter 使用 for-range 替代 VisitAll 遍历头部
- sendfile 添加 nolint 注释说明 buffer pool 设计决策
- defer 关闭文件使用 func() { _ = file.Close() } 确保执行
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 17:36:58 +08:00
351f477822
feat(middleware): 增强 rewrite 安全性,添加 ReDoS 保护
...
- 新增 validateRegexSafety 检测危险正则模式
- 防止嵌套量词导致的灾难性回溯攻击
- 限制正则模式长度 (max 1000 chars)
- 补充 compression 和 accesslog 文档注释
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 16:57:40 +08:00