b18476b443
fix(lua): 修复协程上下文设置问题
...
使用执行上下文(ExecutionContext)替代 RequestCtx 作为 LState 上下文,
因为 RequestCtx.Done() 依赖服务器连接状态,不适合用于超时控制。
RequestCtx 通过 coro.RequestCtx 字段访问。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 09:51:44 +08:00
f84e2c0e9b
fix(lint): 修复 lua 测试中 unused-parameter 错误
...
将未使用的函数参数 L 改为 _
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 09:51:44 +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
50311518ff
test(lua): 添加协程和字节码编译性能基准测试
...
测试协程创建和字节码编译开销。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 09:24:43 +08:00
7d53cc3dea
feat(lua): 改进子请求父请求数据继承
...
ngx.location.capture 改进:
- 子请求继承父请求的 headers 和 query args
- 支持通过 opts.args 覆盖查询参数
- 通过 LState Context 传递 RequestCtx
- 添加测试验证父请求数据继承
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 09:24:43 +08:00
a87640defb
feat(lua): 实现定时器调度器线程隔离
...
定时器回调在专用 Scheduler LState 中执行,避免并发问题:
- TimerManager 使用回调队列 + 专用 goroutine 执行
- 拒绝带 upvalue 的回调,防止闭包数据竞争
- 优雅关闭:排空队列后退出调度器
- Engine 支持 InitSchedulerLState 和 CloseScheduler
实现 scheduler 模式标志和 API 注册机制。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 09:24:43 +08:00
26f18055ce
feat(lua): 添加 Scheduler 模式下的 API 安全检查
...
为定时器回调上下文注册不安全的 ngx API 时返回错误:
- ngx.ctx: 请求上下文不可用
- ngx.req: 请求 API 不可用
- ngx.resp: 响应 API 不可用
- ngx.var: 变量 API 不可用
- ngx.log: 提供安全版本(不依赖 RequestCtx)
防止定时器回调中误用请求相关 API 导致并发问题。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 09:24:43 +08:00
7f2939a7e0
feat(lua): 集成共享字典、定时器和子请求到引擎
...
扩展 LuaEngine 以支持新的 ngx API:
- 添加 SharedDictManager/TimerManager/LocationManager
- 在 setupNgxAPI 中注册 ngx.shared/timer/location API
- 实现优雅关闭时清理定时器和共享字典
- 提供管理器访问方法和便捷创建接口
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-12 11:21:39 +08:00
a4a820ab24
feat(lua): 实现子请求 API (ngx.location.capture)
...
添加 location 子请求实现:
- LocationManager: location handler 注册与管理
- ngx.location.capture: 发起同步子请求
- 支持 method/body/headers 参数配置
- 返回 status/body/headers 结果结构
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-12 11:21:32 +08:00
026302465d
feat(lua): 实现定时器 API (ngx.timer)
...
添加定时器管理实现:
- TimerManager: 定时器生命周期管理
- ngx.timer.at: 创建一次性定时器
- ngx.timer.running_count: 活跃定时器计数
- ngx.timer.pending_count: 等待执行定时器计数
- 支持定时器取消和优雅关闭
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-12 11:21:24 +08:00
e3e5b1fe83
feat(lua): 实现共享字典 API (ngx.shared.DICT)
...
添加共享内存字典实现,支持并发安全的 key-value 存储:
- SharedDictManager: 管理多个命名的 SharedDict 实例
- SharedDict: 带 LRU 汰出策略的内存字典
- 支持 set/get/add/incr/size/free_space 操作
- 支持带 TTL 的过期机制
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-12 11:21:17 +08:00
bfab449241
feat(lua): 实现 Lua 中间件系统
...
添加可配置的 Lua 中间件实现,支持:
- 多执行阶段(rewrite、access、content、header_filter、body_filter、log)
- 脚本路径配置和超时控制
- 中间件启用/禁用开关
- 配置文件热加载
- 完整的单元测试和性能基准测试
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:34:34 +08:00
b31733f233
refactor(lua): 简化 ngx API 表注册流程
...
将 ngx 表的创建和全局设置提前,避免各 API 注册时重复检查表是否存在。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:34:26 +08:00
6b9df86217
feat(lua): 扩展 ngx.req API 并集成所有 ngx API 到沙箱
...
扩展 API: set_uri, set_uri_args, get_headers, set_header, clear_header, get_body_data, read_body
在 coroutine.SetupSandbox() 中统一注册 ngx.req/resp/var/ctx/log/socket API
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 12:17:35 +08:00
86e5b0e6f1
feat(lua): 实现 ngx.log API 和输出控制
...
提供日志输出、响应输出、HTTP 状态码常量
API: ngx.log, ngx.say, ngx.print, ngx.flush, ngx.exit, ngx.redirect
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 12:17:35 +08:00
51061d68ff
feat(lua): 实现 ngx.var API
...
通过元表实现动态变量读写,支持 nginx 内置变量和自定义变量
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 12:17:35 +08:00
d021b0e9fd
feat(lua): 实现 ngx.ctx API
...
提供请求级上下文存储,每请求独立的 Lua table
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 12:17:34 +08:00
797c4b0a26
feat(lua): 实现 ngx.resp API
...
提供响应操作能力:get_status, set_status, get_headers, set_header, clear_header
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 12:17:34 +08:00
8bac2fdcfa
feat(lua): 实现 Cosocket API 和响应拦截器
...
- ngx.req API 双层边界验证原型
- TCP Cosocket API (connect/send/receive/close)
- Cosocket 状态管理器和连接池
- ResponseInterceptor 响应拦截器
- 完整单元测试覆盖
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 18:30:28 +08:00
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
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
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