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
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
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
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
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
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
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
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
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
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
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
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
dafe96b5a3
style(app): 移除测试文件多余空行
...
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 08:14:07 +08:00
31b3d4d0a3
test(sslutil,utils,version): 添加工具模块测试
...
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 08:12:34 +08:00
a832e48656
test(middleware): 添加 limitrate 中间件测试
...
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 08:12:34 +08:00
4d66dd562f
test(app,mimeutil): 添加应用和 MIME 检测测试
...
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 08:12:34 +08:00
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
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
cfb27a9b9d
style(make): 修复文件末尾缺少换行符
...
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 18:26:26 +08:00
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
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
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
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
bca0ee147e
feat(middleware): 添加 limit_rate 响应速率限制中间件
...
基于令牌桶算法实现响应速率限制,支持:
- 速率和突发流量配置
- 大文件特殊处理策略
- 线程安全的令牌桶实现
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 18:08:24 +08:00
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
e05cf8a674
refactor(version): 模块化版本信息
...
将版本信息从 app.go 移至独立的 version 包,便于多模块引用。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 18:07:21 +08:00
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
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
6d33b9548f
docs: 添加 nginx core 模块功能分析提示
...
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 16:04:46 +08:00
b0ca037cad
test(integration): 添加正则 location 配置集成测试
...
- 测试 ~ 修饰符大小写敏感匹配
- 测试 ~* 修饰符大小写不敏感匹配
- 测试 ^~ 修饰符非正则前缀优先匹配
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 16:04:36 +08:00
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
82658359cb
fix(matcher): 修正 ParseRegexPattern nginx 风格正则解析
...
- ~ 现为大小写敏感正则(之前错误为不敏感)
- ~* 为大小写不敏感正则
- ^~ 为前缀优先匹配(非正则,之前错误标记为正则)
- 更新测试用例匹配正确行为
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 16:04:18 +08:00
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
3d80b12f7d
docs: 为其余模块添加标准化 godoc 注释
...
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 11:23:04 +08:00
13bfc090f7
docs(middleware): 为中间件模块添加标准化 godoc 注释
...
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 11:23:03 +08:00
42a4c8d311
docs(proxy): 为反向代理模块添加标准化 godoc 注释
...
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 11:23:03 +08:00
10f3da0954
docs(matcher): 为 location 匹配引擎添加标准化 godoc 注释
...
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 11:23:03 +08:00
1c3e04afdb
docs(lua): 为 Lua API 模块添加标准化 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
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
0c71a80b5a
docs(proxy): 为反向代理模块添加标准化 godoc 注释
...
为 proxy 包所有文件添加完整文档注释:
- proxy: 反向代理核心(负载均衡、缓存、WebSocket、SSL/TLS)
- headers: X-Forwarded 系列请求头设置
- health: 后端健康检查
- proxy_ssl: 上游 SSL/TLS 配置
- redirect_rewrite: 重定向响应改写
- tempfile_cleaner: 临时文件清理
包级注释详细说明支持的负载均衡算法、故障转移机制、
代理缓存策略、重定向改写模式等核心功能。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 10:59:35 +08:00
6094327620
docs(matcher): 为 location 匹配引擎添加标准化 godoc 注释
...
为 matcher 包所有文件添加完整文档注释:
- conflict: 路径冲突检测器
- exact: 精确路径匹配器(O(1) hash map)
- location: 统一匹配引擎(整合所有策略)
- matcher: 匹配结果和接口定义
- named: 命名捕获组匹配器
- prefix: 普通前缀匹配器
- prefix_priority: 前缀优先匹配器(^~)
- radix: Radix Tree 最长前缀匹配
- regex: 正则表达式匹配器
注释说明匹配优先级顺序(精确 > 前缀优先 > 正则 > 普通前缀),
以及各匹配器的使用方法和性能特点。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 10:59:27 +08:00
ad177e9640
docs(lua): 为 Lua API 模块添加标准化 godoc 注释
...
为所有 Lua API 文件添加完整的包级和函数级文档注释:
- api_balancer: 负载均衡 API(set_current_peer, set_more_tries 等)
- api_ctx: 请求上下文存储 API(ngx.ctx)
- api_location: 子请求捕获 API(ngx.location.capture)
- api_log: 日志输出 API(ngx.log)
- api_req: 请求对象 API
- api_resp: 响应对象 API
- api_shared_dict: 共享字典 API
- api_socket_tcp: TCP socket API
- api_timer: 定时器 API
- api_var: 变量 API
- engine: Lua 引擎核心
- context: 请求上下文管理
- coroutine: 协程调度器
- middleware: 中间件集成
- filter_writer: 响应过滤器
- cache: Lua 脚本缓存
- shared_dict: 共享字典实现
- socket_manager: socket 连接管理
注释格式遵循 Go 官方风格,包含功能说明、参数说明和注意事项。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 10:59:17 +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
c82e6dcdb7
test(matcher): 添加 location 匹配引擎完整测试覆盖
...
- conflict_test.go: 测试 location 冲突检测
- location_test.go: 测试 location 匹配逻辑
- named_test.go: 测试命名捕获组
- prefix_priority_test.go: 测试前缀匹配优先级
- prefix_test.go: 测试前缀匹配
- regex_test.go: 测试正则匹配
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 08:27:24 +08:00
7ef16f2be1
test(lua): 添加 api_shared_dict 和 engine 测试覆盖
...
- api_shared_dict_test.go: 测试 shared_dict API 功能
- engine_test.go: 测试 Lua 引擎初始化和执行
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 08:27:24 +08:00
28be9e7e66
fix(server): 添加 shutdownServers nil ctx 防御性检查
...
防止 ctx 参数为 nil 时导致 panic:
- nil ctx 时使用 context.Background() 作为默认值
- 防御性检查确保函数健壮性
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 08:26:51 +08:00
d856e3c570
fix(lua): 改进 dictReplace key 存在性检查逻辑
...
修复 shared_dict.replace() 方法对过期 key 的判断:
- 区分 key 不存在和 key 存在但已过期的情况
- Get() 返回 val="" 且 expired=false 表示 key 不存在
- 先检查不存在情况,再检查过期情况
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 08:26:50 +08:00
5a5f733cb4
refactor(logging): 将日志格式参数从布尔值改为字符串,支持 json/text/console 格式
...
将 Init 接口从 pretty bool 参数改为 format string 参数,
支持 json(纯 JSON)、text(无颜色 ConsoleWriter)、console(带颜色)三种格式。
简化 AppLogger 实现,统一使用 zerolog 格式化输出。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-17 17:26:08 +08:00