20518495b3
refactor: 删除未使用的辅助函数
...
移除两个保留但实际未调用的函数:
- proxy: 删除 handleWebSocket(WebSocket逻辑已整合到 ServeHTTP)
- variable/ssl: 删除 parsePEMCertificate(证书解析已在其他模块处理)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 11:38:12 +08:00
50a960c539
feat(http2): 实现服务器优雅关闭功能
...
添加 GracefulShutdownTimeout 配置项,实现连接池管理和优雅关闭逻辑:
- HTTP2Config 新增 graceful_shutdown_timeout 字段(默认30秒)
- Server 添加连接池和等待组跟踪活跃连接
- Stop() 方法等待所有连接完成或超时后再退出
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 11:38:01 +08:00
4053634b4c
style(utils): 对齐 HTTPError 变量声明格式
...
对齐预定义 HTTP 错误变量的等号位置,保持代码风格一致。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 11:25:56 +08:00
5bb67f13a0
refactor(app): 使用配置化关闭超时替代硬编码
...
移除硬编码的 shutdownTimeout 变量,改用配置中的 Shutdown.GracefulTimeout
和 Shutdown.FastTimeout:
- handleSignal 从配置读取超时值
- gracefulUpgrade 使用配置的优雅停止超时
- 添加防御性 nil-check 确保配置和服务器实例存在
- Windows 版本同步更新
Windows 和 Unix 平台行为一致化。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 11:25:47 +08:00
0152dd1d35
feat(server): 添加 StopWithTimeout 方法支持自定义超时
...
新增 StopWithTimeout 方法,支持传入自定义超时参数:
- 替代原有固定 5s 超时的 Stop 方法
- timeout <= 0 时自动使用默认 5s
- 原 Stop 方法标记为 Deprecated,内部调用 StopWithTimeout
为配置化关闭超时提供基础设施。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 11:25:39 +08:00
532aa55a9c
feat(config): 添加服务器关闭超时配置
...
添加 ShutdownConfig 结构,支持配置优雅停止和快速停止超时:
- graceful_timeout: SIGQUIT 信号优雅停止超时(默认 30s)
- fast_timeout: SIGINT/SIGTERM 快速停止超时(默认 5s)
包含完整的验证逻辑和 YAML 生成支持。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 11:25:31 +08:00
e1df0ec205
refactor(utils): 提取 HTTP 错误响应辅助函数
...
新增 SendError 和 SendErrorWithDetail 函数,统一处理 HTTP 错误响应,减少重复代码。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 11:12:49 +08:00
8a533ba0ca
refactor(lua): 提取 API 注册辅助函数
...
新增 RegisterAPIMethods 和 RegisterUnsafeAPI 函数,简化 Lua API 批量注册逻辑。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 11:12:49 +08:00
81e26e70ce
refactor(config): 提取枚举和非负数验证辅助函数
...
提取 ValidateEnum 和 ValidateNonNegative 函数,简化重复的验证逻辑。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 11:12:37 +08:00
344bc79f67
fix(server): 添加 Shutdown 超时和 CloseOnShutdown
...
为快速停止添加 5 秒超时防止无限等待,设置 CloseOnShutdown
确保连接在关闭时被正确清理。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 10:59:07 +08:00
e9d747a628
refactor(variable): 提取变量展开核心逻辑
...
提取 expandCore 函数作为变量展开的核心实现,
消除 Expand 和 ExpandString 方法中的重复代码。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 10:59:07 +08:00
96bd4b0ed5
refactor(ssl): 提取证书池加载函数到 sslutil 包
...
将 LoadCACertPool 和 LoadCertPool 函数提取到独立的 sslutil 包,
消除 ssl 和 stream 模块中的重复实现。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 10:58:57 +08:00
019bc80aa4
refactor(proxy): 提取 X-Forwarded 头处理为独立模块
...
提取 ForwardedHeaders 结构体和 SetForwardedHeaders/WriteForwardedHeaders
函数,消除 proxy.go 和 websocket.go 中的重复代码。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 10:58:57 +08:00
68447b9a2c
refactor(lua): 提取 SharedDict 类型检查辅助函数
...
提取 checkSharedDict 函数消除重复的类型检查代码,
使各字典方法实现更加简洁。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 10:58:56 +08:00
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
26ffc6b60d
fix(lint): 修复 Windows 平台文件 lint 错误
...
- 调整 App 结构体字段对齐以优化内存布局
- 添加文件末尾换行符
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
bb77fa6a98
fix(lint): 修复 handler 和 http2 模块 lint 错误
...
- 添加 nolint:errcheck 注释到 defer Close 调用
- 修复 websocket.go 中重复的 nolint 注释格式
- 添加 staticcheck SA1019 nolint 注释到 deprecated WriteScheduler
- 移除 sendfile_linux.go 中未使用的 platformLinux 常量
- 添加文件末尾换行符
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 09:51:30 +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
5dbede27f8
Merge branch 'master' of https://github.com/DefectingCat/lolly
2026-04-12 11:50:35 +08:00
e2c9533247
feat(app,server): 添加 Windows 平台兼容性支持
...
- Windows 平台忽略 POSIX 特有信号 (SIGUSR1/2, SIGHUP, SIGQUIT)
- 热升级功能在 Windows 上为空实现 stub
- 分离平台特定代码到独立文件
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-12 11:46:11 +08:00
92ef122226
refactor(handler): 拆分 sendfile 实现为平台特定文件
...
- Linux 平台保留 sendfile 系统调用的零拷贝实现
- 非 Linux 平台使用普通 IO fallback
- 分离平台特定测试到独立文件
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-12 11:45:46 +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
153982121e
feat(server): 集成 Lua 中间件到服务器生命周期
...
- 在 Server 结构添加 luaEngine 字段
- 实现 buildLuaMiddlewares 按阶段创建中间件
- 在 Start() 初始化 Lua 引擎,Stop/GracefulStop 关闭
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 14:31:48 +08:00
1e545717fb
feat(config): 添加 Lua 中间件配置结构和验证
...
- 定义 LuaMiddlewareConfig、LuaScriptConfig、LuaGlobalSettings
- 添加 validateLua 验证脚本路径、阶段和超时配置
- 添加 lua_config_test.go 测试配置验证逻辑
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 14:31:43 +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
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
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
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
01343ce783
refactor(ssl): 提取客户端验证模式常量
...
将硬编码字符串提取为私有常量,避免魔法字符串重复。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 17:59:22 +08:00
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
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
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
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
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
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