170 Commits

Author SHA1 Message Date
xfy
e7ee9e717d feat(cli): 添加 -g 短参数用于生成默认配置
--generate-config 的短参数形式,便于快速生成配置文件

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 18:30:28 +08:00
xfy
76c2a6028c feat(handler,config): 支持 try_files 动态后缀 ($uri.<ext>)
- 实现 $uri.<ext> 模式解析(如 $uri.html, $uri.json)
- 添加扩展名安全验证:白名单字符、危险后缀黑名单
- 根路径边界处理:避免生成 "/.html" 隐藏文件名
- 增强配置文档注释,说明 nginx 兼容性和安全限制
- 完整单元测试覆盖

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 18:30:28 +08:00
xfy
ada7357f7d feat(docker,server): 改进容器信号处理和优雅关闭
- 使用 tini 作为 PID 1 init 进程,处理僵尸进程回收和信号转发
- 多次 SIGINT (3次) 支持强制退出
- GoroutinePool.Stop() 添加 5s 超时等待,防止无限阻塞
- GracefulUpgrade 启动 goroutine 等待子进程,避免僵尸进程
- 关闭父进程文件描述符副本,防止泄漏

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 18:30:28 +08:00
xfy
1ed56bd9c4 chore(ci): 移除 benchmark 工作流配置
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 18:19:44 +08:00
xfy
d0eaeed334 docs: 移除 .github 目录下的 AGENTS.md 文件
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 18:19:39 +08:00
xfy
7ebf8087e4 chore(deps): 添加 goleak 间接依赖
用于 goroutine 泄漏检测测试。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 17:59:22 +08:00
xfy
6543422281 docs: 添加 Nginx 配置和 Lua 脚本示例文档
- config: 反向代理、缓存、负载均衡、安全、SSL 等配置模板
- lua: API 网关、认证、动态路由、限流、WebSocket 等脚本示例

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 17:59:22 +08:00
xfy
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
xfy
01343ce783 refactor(ssl): 提取客户端验证模式常量
将硬编码字符串提取为私有常量,避免魔法字符串重复。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 17:59:22 +08:00
xfy
8180ee9bea fix(proxy): 修复 WebSocket 升级失败时的资源泄漏
在升级失败(状态码非 101)和写入响应失败时,确保 resp.Body.Close()。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 17:59:22 +08:00
xfy
1ab49af76d chore(lint): 重构 golangci 配置,重新启用多项检查
重新启用 bodyclose、errorlint、contextcheck、prealloc、unconvert 等检查,
按类别整理禁用项,添加细粒度排除规则。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 17:58:34 +08:00
xfy
55c05ec41d feat(docker): 添加容器化部署支持
- Dockerfile: 多阶段构建,最小化镜像体积(scratch)
- docker-compose.yml: 开发环境配置,含健康检查
- .dockerignore: 排除不必要的构建上下文

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 16:56:10 +08:00
xfy
2def9817d8 docs(proxy,resolver): 修复注释格式和代码风格
- 调整 stats.go 文档注释缩进格式
- 规范 protoHTTPS 常量对齐

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 16:55:48 +08:00
xfy
52a210ed19 chore(config): 调整 golangci-lint 和 Makefile 配置
golangci.yml:
- 排除 lua 包的 revive stuttering 检查
- 配置 revive exported 规则禁用 stuttering 检查

Makefile:
- 简化构建命令,移除冗余的 build 和 build-prod 区分
- 默认 build 使用最大性能优化构建

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 16:55:47 +08:00
xfy
7156bbc82f refactor(lua): 改进代码风格和文档注释
- 为 LuaEngine/LuaContext/LuaCoroutine 添加命名说明注释
- 为 Phase 常量添加文档注释
- 规范 import 排序顺序
- 处理 Write 返回值避免 lint 警告
- 修复文件末尾换行符

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 16:55:38 +08:00
xfy
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
xfy
fdab778896 feat(mimeutil): 添加 MIME 类型检测工具包
提供 DetectContentType 函数,补充 Go 标准库缺失的 MIME 类型映射。
使用包本地映射而非全局 mime.AddExtensionType,避免副作用。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 16:55:37 +08:00
xfy
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
xfy
aa05d6b965 feat(lua): 在沙箱中阻止危险的协程创建函数
添加 setupSecureCoroutineLib 函数,在沙箱环境中拦截 coroutine.create/wrap/resume/running,
仅保留 yield/status 安全函数。防止脚本创建不受控制的协程。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 14:56:13 +08:00
xfy
7a66e350f0 feat(lua): 添加 Lua 脚本嵌入支持
- 基于 gopher-lua 实现类似 OpenResty 的脚本嵌入能力
- LuaEngine: server 级单 LState + 请求级临时协程
- LuaContext: 请求上下文,变量存储和阶段管理
- LuaCoroutine: 沙箱隔离,Yield/Resume 循环,执行超时
- CodeCache: 字节码缓存,LRU 淘汰 + TTL 过期
- 新增 testify 用于测试断言

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 14:19:03 +08:00
xfy
d22c20cbbb feat(server): 添加 AuthRequest 外部认证中间件
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 13:22:35 +08:00
xfy
bab0228e1d refactor(security): 将安全头辅助函数改为私有
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 13:22:35 +08:00
xfy
7f4c8f547c refactor(compression): 移除 TryServeFile 和 DefaultExtensions 公开函数
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 13:22:35 +08:00
xfy
5e86f47650 refactor(bodylimit): 将 FormatSize 改为私有函数 formatSize
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 13:22:35 +08:00
xfy
941c44b798 docs: 添加 Lua 嵌入分析文档
- 新增 lua-embed-analysis.md 技术分析文档
- 新增 lua-nginx-module 文档目录
- 更新 gitignore 允许跟踪 docs/lua-nginx-module/

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 11:20:57 +08:00
xfy
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
xfy
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
xfy
a965040eff refactor(handler): 提取平台字符串为常量
- 使用 platformLinux 常量替代硬编码字符串 "linux"

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 11:20:35 +08:00
xfy
a10377f76d refactor(config): 提取常量并删除未使用代码
- 新增 DefaultPprofPath 常量替代硬编码路径
- 删除 validate.go 中未使用的 parseSize() 函数

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 11:20:27 +08:00
xfy
931144dd08 refactor(cache): 统一路径匹配函数并增强通配符支持
- 删除 file_cache.go 中的 pathMatch() 函数
- 导出 purge.go 中的 MatchPattern() 函数
- 增强 MatchPattern() 支持中间通配符(如 /api/*/users)
- 使用 netutil.ExtractClientIPNet() 替代内联 IP 提取逻辑
- 适配 status 模块使用新的工具函数

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 11:20:19 +08:00
xfy
616762e840 refactor(netutil): 提取通用主机名处理函数
- 新增 StripPort() 函数用于移除主机名中的端口
- 新增 HasPort() 函数用于检测主机名是否包含端口
- 替代 vhost 和 ssl 模块中的内联端口处理逻辑

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 11:20:10 +08:00
xfy
f0f0f7b821 chore(gitignore): 添加 lua-nginx-module 排除规则
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 10:21:50 +08:00
xfy
e430400a24 docs: 更新项目统计数据
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 10:10:12 +08:00
xfy
904efa9842 chore(release): 发布 v0.2.0 版本
- 更新 CHANGELOG 记录所有新增功能和变更
- 版本号升级至 0.2.0
- 调整 Makefile 构建命令结构

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
v0.2.0
2026-04-10 09:48:35 +08:00
xfy
d1f27002e0 chore(golangci): 调整配置结构,迁移排除规则
将 issues.exclude-rules 移至 linters.exclusions.rules
格式统一化,移除冗余配置项

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:41:07 +08:00
xfy
4e826925ac refactor: 适配核心模块类型重命名
适配 variable.NewContext/ReleaseContext
适配 resolver.DNSCacheEntry
适配 logging/formatJSON 常量

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:41:07 +08:00
xfy
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
xfy
ac8e89c492 refactor(http3): 适配 resolver.DNSCacheEntry 重命名
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:57 +08:00
xfy
239635301c refactor(http2): 适配变量系统和 resolver 重命名
适配 variable.NewContext/ReleaseContext
适配 resolver.DNSCacheEntry

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:57 +08:00
xfy
d89e55481c refactor(ssl): 适配 resolver.DNSCacheEntry 重命名
适配 resolver 模块类型重命名

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:48 +08:00
xfy
7950f17da5 refactor(server): 适配变量系统重命名
适配 variable.NewContext/ReleaseContext 重命名

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:47 +08:00
xfy
4c12703334 style(loadbalance): 使用自增运算符替代显式加法
totalWeight += 1 → totalWeight++

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:47 +08:00
xfy
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
xfy
3e153f5fe1 refactor(logging): 提取命名常量并适配变量系统重命名
提取 formatJSON 常量替代硬编码 "json"
适配 variable.NewContext/ReleaseContext 重命名

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:38 +08:00
xfy
1ce84ce9c5 refactor(proxy): 提取命名常量并适配变量系统重命名
提取硬编码字符串为命名常量:
- upstreamCache = "CACHE"
- protoHTTPS = "https"
ProxyWebSocket → WebSocket
适配 variable.Context 重命名

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:37 +08:00
xfy
b28ad378fa refactor(resolver): 重命名核心类型移除冗余前缀
ResolverStats → Stats
dnsCacheEntry → DNSCacheEntry (导出以符合 Go 命名规范)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:26 +08:00
xfy
4e535deb80 refactor(stream): 重命名 SSL 管理器类型移除冗余前缀
StreamSSLManager → SSLManager
StreamProxySSLManager → ProxySSLManager

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:26 +08:00
xfy
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
xfy
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
xfy
7a2b1d7e03 chore(makefile): 使用 goimports 替代 go fmt 格式化代码
goimports 可同时处理格式化和导入排序。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 17:58:18 +08:00