675 Commits

Author SHA1 Message Date
xfy
dd6b61f987 test(e2e): 添加 SSL/TLS E2E 测试框架
- e2e_test.go: E2E 测试基础设施初始化
- ssl_e2e_test.go: SSL 握手、TLS 版本、加密套件、mTLS 测试
- 使用 testcontainers-go 进行容器化测试

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 14:59:21 +08:00
xfy
604bc719f9 test(integration): 添加缓存和代理集成测试
- cache_integration_test.go: 缓存创建、存取、过期、stale、并发测试
- proxy_integration_test.go: 代理创建、负载均衡、超时、健康检查测试

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 14:59:12 +08:00
xfy
ad88770472 deps: 添加 testcontainers 测试依赖
- 添加 testcontainers-go 用于 E2E 测试
- 引入 Docker 容器化测试基础设施依赖

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 14:59:01 +08:00
xfy
cc19328a81 ci: 添加分层测试 CI 工作流
- 添加 GitHub Actions 工作流支持 L1/L2/L3 三层测试
- Makefile 新增 test-integration、test-e2e、test-all 目标
- 支持单元测试、集成测试、E2E 测试分离执行

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 14:58:52 +08:00
xfy
00c5319819 refactor(proxy,server): 改进健康检查 goroutine 退出机制
- health: 使用 WaitGroup 确保 run goroutine 完全退出后再继续
- health_match: 忽略未使用参数,预分配 slice 容量
- proxy_coverage_extra_test: 使用 atomic.Int32 修复测试竞态条件
- purge: 忽略 Delete 返回值

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 13:35:03 +08:00
xfy
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
xfy
91d67ad384 refactor(cache,config): 代码清理和优化
- disk_cache: 忽略 filepath.Walk 和 Delete 返回值
- tiered_cache: 忽略 l1.Delete 返回值,删除未使用的 revalidate 函数
- config: 简化 multiplier 变量声明

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 13:34:51 +08:00
xfy
92b7040a5f feat(proxy,config): 增强健康检查和缓存配置
健康检查增强:
- 添加 HealthMatch 接口支持自定义健康判断逻辑
- 支持状态码范围、响应体正则、响应头匹配
- 集成 SlowStartManager 实现慢启动

配置增强:
- HealthCheckConfig 新增 Match 和 SlowStart 字段
- ProxyBufferingConfig 支持 Buffers 配置字符串格式
- 新增 ProxyCachePathConfig 磁盘缓存路径配置
- 添加 StaleIfError/StaleIfTimeout 缓存配置

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 13:15:18 +08:00
xfy
26a7a58265 feat(loadbalance): 实现慢启动功能
- 添加 SlowStartManager 统一管理目标慢启动状态
- Target 新增 EffectiveWeight 和 SlowStart 字段
- 实现 GetEffectiveWeight 方法支持动态权重
- 权重从 1 线性增加到配置权重,防止恢复服务器被压垮

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 13:15:09 +08:00
xfy
aae378433e feat(cache): 实现分层缓存架构
- 添加 CacheBackend 接口统一内存/磁盘缓存访问
- 实现 DiskCache 磁盘缓存后端,支持目录层级和原子写入
- 实现 TieredCache 分层缓存(L1 内存 + L2 磁盘)
- 修改 ProxyCache.Delete 返回 error 以符合接口
- 添加 CacheStats() 方法实现接口

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 13:15:02 +08:00
xfy
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
xfy
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
xfy
4697f39924 refactor(proxy): 消除缓存处理中的 goto 语句
重构 ServeHTTP 中的缓存逻辑,用嵌套 if 结构替代 goto proxyRequest,
使控制流更清晰。主要变更:
- 缓存命中逻辑内聚到 rule != nil 分支
- 缓存锁等待后重新检查缓存命中
- 移除 proxyRequest 标签

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 08:08:44 +08:00
xfy
d933c1bd98 refactor(cache): 提取 MatchRule 辅助函数并扩展测试
将 MatchRule 拆分为 matchPath/matchMethod/matchStatus 三个辅助函数,
提升代码可读性和可测试性。新增测试覆盖:
- AcquireLockWithTimeout 锁超时机制
- RefreshTTL TTL 刷新功能
- SetValidationHeaders 验证头设置
- MatchRule 路径匹配变体(前缀/通配符/精确)
- min_uses 计数阈值

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 08:08:37 +08:00
xfy
0a7f7170d5 feat(cache,proxy): 增强代理缓存功能
- 添加 min_uses 阈值支持,请求次数达标才缓存
- 添加 cache_lock_timeout 配置,防止缓存锁无限等待
- 添加条件请求支持 (If-Modified-Since/If-None-Match),处理 304 响应
- 添加 background_update_disable 配置,允许禁用后台更新
- 添加 cache_ignore_headers 配置,缓存时忽略指定响应头
- 添加 methods 配置,指定可缓存的 HTTP 方法
- 改进路径匹配逻辑,支持精确匹配和通配符匹配

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 18:23:20 +08:00
xfy
48d8c06e31 fix(config): 补充默认值并同步 GenerateConfigYAML 输出
为 GeoIP/AuthRequest 添加默认值,GenerateConfigYAML 中硬编码值改为从配置读取,
补充 types/limit_rate/proxy_bind/buffering/internal 等字段文档输出,
新增默认值和字段覆盖测试。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 15:10:52 +08:00
xfy
8baee13503 fix(proxy,config): 修复 HealthChecker 重启支持和补充 random 算法文档
Stop 后重建 stopCh 以支持再次 Start;config 注释补充 random 算法。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 11:41:16 +08:00
xfy
11f9cebcd5 fix(proxy): 修复 ProxyBind 拨号超时和 Cookie 属性匹配
ProxyBind 使用 MaxConnWaitTimeout 作为拨号超时不合理,改为默认 30s;
rewriteCookieAttr 属性匹配改为大小写不敏感;预分配 cookies 切片容量。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 11:41:03 +08:00
xfy
b6e9772191 refactor(loadbalance): 用互斥锁替代原子操作保护 Target 失败状态
原子 CAS 操作在 IsAvailable/RecordFailure/RecordSuccess 之间存在协调问题,
改用 sync.Mutex 保护 failCount 和 failedUntil 的联合更新,简化逻辑并保证一致性。
同时预分配 backups 切片容量避免多次内存分配。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 11:40:50 +08:00
xfy
ce2d11197a test(loadbalance,proxy): 添加上游参数和 random 算法测试
新增 IsAvailable/RecordFailure/RecordSuccess/filterHealthy 备份优先级、
Random 负载均衡算法测试,适配 createHostClient 签名变更。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 11:28:59 +08:00
xfy
2b63666ea5 feat(proxy,server): 实现 ProxyBind/Buffering/ProxyURI 和响应头控制
ProxyBind 支持指定本地地址出站连接,Buffering 控制响应缓冲模式,
ProxyURI 实现 nginx proxy_pass URI 替换语义,
响应头新增 HideResponse/PassResponse/IgnoreHeaders/Cookie 域路径重写,
健康检查集成 RecordFailure/RecordSuccess 软失败状态。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 11:28:32 +08:00
xfy
c0b7e30bf0 feat(config,loadbalance): 添加上游服务器参数和 random 负载均衡算法
Target 新增 MaxConns/MaxFails/FailTimeout/Backup/Down/ProxyURI 字段,
实现 IsAvailable/RecordFailure/RecordSuccess 软失败机制,
filterHealthy 支持备份服务器优先级选择,
新增 random(Power of Two Choices)负载均衡算法。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 11:28:02 +08:00
xfy
dafe96b5a3 style(app): 移除测试文件多余空行
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 08:14:07 +08:00
xfy
31b3d4d0a3 test(sslutil,utils,version): 添加工具模块测试
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 08:12:34 +08:00
xfy
a832e48656 test(middleware): 添加 limitrate 中间件测试
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 08:12:34 +08:00
xfy
4d66dd562f test(app,mimeutil): 添加应用和 MIME 检测测试
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 08:12:34 +08:00
xfy
7a96db9f05 test(server): 重构并扩展服务器测试
- 拆分 server_extended_test.go 到独立测试文件
- 添加 pprof、purge、vhost、internal 测试

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 08:12:33 +08:00
xfy
9f3524f641 test(http2,http3): 添加 HTTP/2 和 HTTP/3 服务器测试
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 08:12:33 +08:00
xfy
cfb27a9b9d style(make): 修复文件末尾缺少换行符
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 18:26:26 +08:00
xfy
e9c24e5671 chore(make): 增强 clean 目标清理 Go 缓存
添加 go clean -cache -testcache 清理构建缓存,
注释保留 go clean -modcache 供需要时启用。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 18:25:46 +08:00
xfy
08e6e8c003 docs: 更新 CHANGELOG 和 Dockerfile
CHANGELOG 记录 Unreleased 新功能:
- internal 指令
- limit_rate 中间件
- server_tokens 配置
- types 配置块

Dockerfile 更新版本信息路径。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 18:09:08 +08:00
xfy
ae0bec6c3b feat(internal): 实现 internal 指令
- 新增 IsInternalRedirect 检测内部重定向请求
- static handler 支持 internal 访问限制
- proxy handler 支持 internal 访问限制
- 支持 X-Accel-Redirect 内部重定向

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 18:09:06 +08:00
xfy
3033d57764 feat(server): 实现 server_tokens 和 types 配置
- getServerName: 根据 ServerTokens 控制版本号显示
- applyTypesConfig: 应用自定义 MIME 类型配置
- 更新 location 添加方法调用

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 18:08:25 +08:00
xfy
bca0ee147e feat(middleware): 添加 limit_rate 响应速率限制中间件
基于令牌桶算法实现响应速率限制,支持:
- 速率和突发流量配置
- 大文件特殊处理策略
- 线程安全的令牌桶实现

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 18:08:24 +08:00
xfy
65080cca66 feat(matcher): 支持 internal location 标记
- MatchResult 新增 Internal 字段
- AddExact/AddPrefix/AddPrefixPriority/AddRadix/AddRegex 方法新增 internal 参数
- location 解析器支持 internal 指令

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 18:08:23 +08:00
xfy
e05cf8a674 refactor(version): 模块化版本信息
将版本信息从 app.go 移至独立的 version 包,便于多模块引用。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 18:07:21 +08:00
xfy
d7e7b36048 feat(config): 添加 limit_rate、types、server_tokens 配置
- LimitRateConfig: 响应速率限制配置
- TypesConfig: 自定义 MIME 类型映射
- ServerTokens: 控制 Server 响应头版本号显示
- Internal: location 内部访问限制标记

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 18:07:20 +08:00
xfy
fe6d129ae2 feat(mimeutil): 添加线程安全的 MIME 类型配置
新增 AddTypes、SetDefaultType、GetDefaultType 函数,
支持运行时动态配置 MIME 类型映射。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 18:07:20 +08:00
xfy
6d33b9548f docs: 添加 nginx core 模块功能分析提示
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 16:04:46 +08:00
xfy
b0ca037cad test(integration): 添加正则 location 配置集成测试
- 测试 ~ 修饰符大小写敏感匹配
- 测试 ~* 修饰符大小写不敏感匹配
- 测试 ^~ 修饰符非正则前缀优先匹配

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 16:04:36 +08:00
xfy
4b6bc056bc feat(config): 添加 location_type 配置验证
- 验证 location_type 枚举值有效性
- regex/regex_caseless 类型时验证 path 为有效正则
- named 类型时验证 location_name 必填

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 16:04:26 +08:00
xfy
82658359cb fix(matcher): 修正 ParseRegexPattern nginx 风格正则解析
- ~ 现为大小写敏感正则(之前错误为不敏感)
- ~* 为大小写不敏感正则
- ^~ 为前缀优先匹配(非正则,之前错误标记为正则)
- 更新测试用例匹配正确行为

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 16:04:18 +08:00
xfy
5354dceaf7 fix(lua): 修复 remote_port 和 server_port 变量返回空值
- 实现 remote_port 从 RemoteAddr 正确解析端口
- 实现 server_port 从 LocalAddr 正确解析端口
- 使用 strings.LastIndex 兼容 IPv4/IPv6 地址格式

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 16:03:41 +08:00
xfy
3d80b12f7d docs: 为其余模块添加标准化 godoc 注释
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 11:23:04 +08:00
xfy
13bfc090f7 docs(middleware): 为中间件模块添加标准化 godoc 注释
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 11:23:03 +08:00
xfy
42a4c8d311 docs(proxy): 为反向代理模块添加标准化 godoc 注释
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 11:23:03 +08:00
xfy
10f3da0954 docs(matcher): 为 location 匹配引擎添加标准化 godoc 注释
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 11:23:03 +08:00
xfy
1c3e04afdb docs(lua): 为 Lua API 模块添加标准化 godoc 注释
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 11:23:03 +08:00
xfy
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
xfy
088785bce2 docs(logging): 为日志模块添加标准化 godoc 注释
为 logging 包添加完整的包级和函数级文档:
- Init: 全局日志初始化
- New: 创建日志管理器(支持访问/错误日志分离)
- LogAccess: 记录访问日志
- NewAppLogger: 创建应用日志管理器
- Error/Info/Warn/Debug: 日志级别方法

注释说明支持的日志格式(console、text、json)
和级别(debug、info、warn、error)。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 10:59:42 +08:00