395 Commits

Author SHA1 Message Date
xfy
be974b2e18 feat(proxy,config): 代理层集成 stale 缓存回退逻辑
上游请求失败时,根据错误类型(超时/其他)调用 GetStale 尝试返回
过期缓存。配置文件示例补充 stale_if_error 和 stale_if_timeout 字段。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-24 10:06:27 +08:00
xfy
8deda73b24 feat(cache): 添加 stale_if_error 和 stale_if_timeout 缓存接口和实现
在 CacheBackend 接口新增 GetStale 方法,支持上游错误时按错误类型
(超时 vs 其他错误)检查对应的 stale 窗口返回过期缓存。
ProxyCache、DiskCache、TieredCache 均实现该方法。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-24 10:05:39 +08:00
xfy
c6df735caa feat(make): 添加 act 命令用于本地运行 CI
- make act: 运行完整 CI
- make act-unit: 仅运行单元测试 job

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-24 08:11:05 +08:00
xfy
6686b8557d fix(ci): 修复 act 本地运行 CI 测试失败的问题
- 修复 captureStdout/captureStderr 管道死锁问题,使用 goroutine 异步读取
- 添加 root 用户跳过权限测试的逻辑(act 容器以 root 运行)
- 更新 golangci-lint 到 v2.11.4 并迁移配置格式
- 更新 golangci-lint-action 到 v7
- 添加 linter continue-on-error 避免阻塞 CI

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-23 19:33:35 +08:00
Sonetto
bcd44db707
Merge pull request #1 from DefectingCat/feat/docker-integration-tests
feat(test): 添加 Docker 集成测试和 E2E 测试框架
2026-04-23 18:09:27 +08:00
xfy
fa74074bc7 refactor(e2e): 简化 HTTP/2 测试为 HTTPS 连接测试
- 移除 HTTP/2 协议特定测试(流多路复用、头部压缩、服务器推送等)
- 重命名测试函数 TestE2EHTTP2* → TestE2EHTTPS*
- 使用 testutil.CreateTLSClient 简化客户端创建
- 移除 golang.org/x/net/http2 依赖

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-23 18:02:36 +08:00
xfy
b34fae5885 test(resolver): 添加 DNS 解析器 Mock 测试
- 添加缓存、LRU 淘汰、刷新循环测试
- 添加并发访问、超时处理测试

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-23 17:20:32 +08:00
xfy
f91a40cc1d test(lua): 添加边界场景和 Scheduler 模式测试
- 添加协程沙箱、定时器句柄、共享字典容量边界测试
- 添加 Scheduler 模式 API 安全限制测试

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-23 17:20:32 +08:00
xfy
e145f1b080 test(http2): 添加 HTTP/2 E2E 和 TLS 集成测试
- 添加 HTTP/2 协议协商、流多路复用、头部压缩 E2E 测试
- 添加 TLS 握手、ALPN 协商、HTTP/1.1 回退集成测试

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-23 17:20:21 +08:00
xfy
2ffcfd782b style(e2e): 清理代码格式和未使用的导入
- 删除 loadbalance_e2e_test.go 中未使用的 encoding/json 导入
- 删除 ssl_e2e_test.go 中未使用的 net/http 导入
- 格式化 testutil/config.go 中的结构体字段对齐
- 为多个文件添加末尾换行符

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-23 15:36:42 +08:00
xfy
9eaa77478a test(e2e): 添加缓存、健康检查、负载均衡和 WebSocket E2E 测试
扩展 SSL E2E 测试覆盖更多场景。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-23 14:51:25 +08:00
xfy
0790c5a9e4 test(e2e/testutil): 扩展测试工具包
添加配置生成、常量定义、测试设置、SSL 和 WebSocket 工具函数。
重构 container.go 支持函数式选项模式配置容器。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-23 14:51:11 +08:00
xfy
66060928d1 deps: 添加 gorilla/websocket 依赖
用于 WebSocket E2E 测试。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-23 14:51:11 +08:00
xfy
4562dd5a7d docs: 添加子目录 AGENTS.md 文档
deepinit 生成的子目录级 AGENTS.md 文件,帮助 AI agents 理解各功能模块:
- docs/config/: advanced, basic, caching, load-balancing, lua, rewriting, security, ssl
- docs/lua/: api-gateway, authentication, caching, dynamic-routing, logging-monitoring, middleware, rate-limiting, websocket

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-23 10:35:49 +08:00
xfy
76ab9bcb24 refactor(e2e): 统一 E2E 测试以 lolly 为被测系统
- 将 StartNginxContainer 重命名为 StartMockBackend,明确其作为模拟后端的用途
- proxy_e2e_test.go: 所有测试使用 lolly 作为代理,nginx 作为后端
- ssl_e2e_test.go: 移除 nginx 容器测试,简化为 lolly SSL 功能测试
- static_e2e_test.go: 所有测试使用 lolly 作为静态文件服务器

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-23 10:25:56 +08:00
xfy
be58730c52 test(e2e): 添加代理和静态文件 E2E 测试
- proxy_e2e_test.go: 测试代理转发、负载均衡
- static_e2e_test.go: 测试静态文件服务、目录索引

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-23 09:35:31 +08:00
xfy
e5b494c058 refactor(e2e): 简化 SSL E2E 测试代码
使用 testutil 工具包重构,减少重复代码

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-23 09:35:25 +08:00
xfy
5d38d9ab44 test(e2e): 添加 E2E 测试工具包和配置
- 添加 testutil 容器管理工具(lolly/nginx)
- 添加测试配置文件(basic/proxy/ssl)
- 添加测试用 SSL 证书

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-23 09:35:19 +08:00
xfy
8f79fb6797 test(config,handler,loadbalance,proxy): 扩展单元测试覆盖率
添加以下测试:
- validate_test.go: Rewrite、NextUpstream、DefaultServer、Mode、
  ListenConflicts、HTTP2、RedirectRewrite 验证测试
- sendfile_test.go: 无效文件描述符、零长度传输、部分传输、
  带偏移量传输测试
- balancer_test.go: ConsistentHash Select/SelectExcluding、
  RandomBalancer 边界条件和 Power of Two Choices 测试
- health_test.go: MarkHealthy/MarkUnhealthy 与 SlowStartManager
  集成测试

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 18:28:28 +08:00
xfy
cae8856f11 build(make): 将 check 目标改为使用 test-all
将 check 目标从 test 改为 test-all,确保运行完整测试套件
(包括单元测试、集成测试和 E2E 测试)。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 18:28:15 +08:00
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