1b40a72632
test(server): 添加性能基准测试
...
为 server 模块添加 benchmark 测试:
- middleware: Panic 恢复、超时控制、请求体限制
- pool: Goroutine 池任务提交、并发处理
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 10:49:38 +08:00
d1da187acc
test(http3,logging,netutil,resolver,stream): 添加性能基准测试
...
为核心模块添加 benchmark 测试:
- http3: Handler 包装、请求/响应转换、Body 读取
- logging: JSON/模板访问日志、变量展开
- netutil: TCPKeepAlive 配置解析
- resolver: DNS 解析性能
- stream: 健康过滤、UDP 会话、负载均衡
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 10:49:38 +08:00
322573b9aa
test(http2,http3,proxy): 改进测试覆盖边界情况
...
- http2/adapter_test.go: 替换 pool reuse 测试,新增 header 转换边界测试
- 空头测试、特殊字符、多值头、长头名称
- http3/server_test.go: 替换 stats struct 测试,新增 Alt-Svc 头边界测试
- 端口边界值、禁用服务器、nil 配置
- http3/mock_test.go: 添加 QUIC listener mock 用于测试
- proxy/proxy_test.go: 添加 UpstreamTiming 边界测试
- 零值测试、部分标记测试
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 17:38:59 +08:00
9144dcbb06
refactor(server): 提取初始化逻辑到独立函数
...
- 将 Start() 中的 goroutine pool 初始化提取为 initGoroutinePool()
- 将 file cache 初始化提取为 initFileCache()
- 将 Lua engine 初始化提取为 initLuaEngine()
- 将 error page manager 初始化提取为 initErrorPageManager()
- 添加 init.go 存放提取的初始化函数
- 添加 init_test.go 测试初始化函数
- 添加 testutil.go 提供测试 mock 和工具
- 添加 lua_integration_test.go Lua 中间件集成测试
- 添加 start_integration_test.go Start() 集成测试
- 添加 server_test.go nil tlsManager 测试
- 添加 lua/mock_engine.go Lua 引擎 mock 实现
- 添加 lua/api_balancer_test.go Lua balancer API 测试
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 17:38:49 +08:00
73ef7f4916
fix(lint): 修复剩余 lint 错误
...
- 统一八进制权限格式为 Go 1.13+ 风格 (0o644/0o755)
- 调整 Target 结构体字段顺序优化内存对齐
- 合并相邻的全局变量声明
- 删除多余空行
- 更新 Makefile 使用 gofumpt 替代 goimports
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 16:50:14 +08:00
0c8a15cfee
fix(lint): 调整 Target 结构体字段顺序优化内存对齐
2026-04-13 16:41:20 +08:00
5b41c3ab44
refactor(server): 使用 NewTargetFromConfig 简化目标创建
2026-04-13 16:40:50 +08:00
b722cbf884
style: 统一八进制权限格式和代码格式
2026-04-13 16:40:50 +08:00
ef652cdab1
feat(static): 添加符号链接安全检查功能
2026-04-13 16:40:50 +08:00
bdf615c585
fix(loadbalance): 添加 hostnameOnce 确保并发安全
...
Target 结构体添加 sync.Once 字段,确保 hostname 初始化的并发安全
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 16:21:21 +08:00
d0396a3854
fix(stream): 添加 SSL 证书验证禁用的安全警告
...
当 verify=false 跳过证书验证时,打印警告日志提醒中间人攻击风险
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 16:20:20 +08:00
1bf9e7ad5d
fix(test,security): 改进测试稳定性和认证安全性
...
- socket_test.go: 降低压力测试参数避免超时,改进连接状态等待逻辑
- auth.go: 使用 subtle.ConstantTimeCompare 替代手动循环比较
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 16:20:01 +08:00
d21e27fbac
fix(lint): 修复 golangci-lint 错误 (119 -> 0 issues)
...
主要修复:
- errcheck: defer Close 使用 //nolint:errcheck,类型断言改为 ok 检查
- govet fieldalignment: 调整结构体字段顺序优化内存布局
- revive unused-parameter: 将未使用参数改为 _
- exhaustive: 添加缺失的 switch case 或 default
- goconst: 提取重复字符串为常量 (accessAllow, accessDeny 等)
- staticcheck SA9003: 修复空分支逻辑
- gofmt: 运行 gofmt -w 格式化
- nolintlint: 修复 nolint 注释格式
其他改进:
- 更新 .golangci.yml 配置,启用更严格的检查
- 移除未使用的代码和导入
- 简化测试辅助函数调用
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 16:15:31 +08:00
f31e8afeff
feat(lua): 添加 balancer_by_lua 动态负载均衡功能
...
- 新增 BalancerByLuaConfig 配置,支持 Lua 脚本控制后端选择
- 实现 api_balancer.go Lua API,暴露 set_current_peer 等函数
- Proxy 集成 Lua 引擎,fallback 到标准算法确保可靠性
- 添加负载均衡算法常量提取,消除魔法字符串
- 支持超时控制和备用算法配置
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 16:14:59 +08:00
103e8ff0cf
feat(geoip): 添加基于国家代码的 GeoIP 访问控制功能
...
- 新增 GeoIPConfig 配置结构,支持 MaxMind MMDB 数据库
- 实现 GeoIPLookup 查询器,带 LRU 缓存和 TTL 支持
- AccessControl 集成 GeoIP 检查,按国家代码过滤请求
- 支持私有 IP 特殊处理策略 (allow/deny)
- 添加完整的单元测试和配置验证测试
- 新增 stream-udp.conf 示例配置文档
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 16:14:44 +08:00
4f6a7be44c
docs: 更新 AGENTS.md 项目文档
...
- 更新各目录 AGENTS.md 的子目录信息
- 添加新增目录的 AGENTS.md 文件
- 更新 docs/prompts.md 添加新的提示词
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 13:15:39 +08:00
75b0d0758b
fix(config): 添加缺失的 Lua 配置默认值
...
- 补充 LuaMiddlewareConfig 默认配置
- 添加 Status.Format 字段默认值
- 简化验证逻辑
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 13:15:31 +08:00
742e261fdc
fix(lint): 删除 cache_test.go 中未使用的测试函数
...
移除 TestContains 和 TestContainsInt,对应的辅助函数已删除
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 13:15:26 +08:00
e646cc5d05
refactor(test): 提取 testutil 包统一测试辅助函数
...
- 新增 NewRequestCtx 和 NewRequestCtxWithHeader 辅助函数
- 简化各测试文件中 RequestCtx 创建代码
- 减少测试代码重复,提高可维护性
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 13:15:20 +08:00
95b6119e34
refactor: 使用标准库 slices/maps 替代自定义函数
...
- 使用 slices.Contains 替代 contains/containsInt 函数
- 使用 maps.Copy 替代手动遍历复制
- 删除 internal/cache 中不再需要的辅助函数
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 13:15:13 +08:00
78c49f7288
fix(lint): 修复代码清理和lint警告
...
- 移除 proxy.go 未使用的 protoHTTPS 常量
- 修复 api_shared_dict.go 无效赋值警告
- 修复 certpool.go unused-parameter 警告
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 11:44:04 +08:00
6a08a6ab4a
fix(lint): 修复结构体字段对齐问题
...
调整 Config、Server、APIMethod 结构体字段顺序以优化内存布局,
解决 govet fieldalignment 检查警告。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 11:43:57 +08:00
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