00c5319819
refactor(proxy,server): 改进健康检查 goroutine 退出机制
...
- health: 使用 WaitGroup 确保 run goroutine 完全退出后再继续
- health_match: 忽略未使用参数,预分配 slice 容量
- proxy_coverage_extra_test: 使用 atomic.Int32 修复测试竞态条件
- purge: 忽略 Delete 返回值
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 13:35:03 +08:00
2bdc8f3b3b
refactor(handler,middleware,server): 增强预压缩配置灵活性
...
- NewGzipStatic 增加 precompressedExtensions 参数,支持自定义预压缩扩展名
- SetGzipStatic 分离源文件扩展名和预压缩扩展名参数
- 更新相关测试用例
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 13:35:03 +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
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
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
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
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
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
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
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
5f60dc9ff7
feat(server): 为静态文件处理添加符号链接安全检查
...
在 registerStaticHandlersWithLocationEngine 和 registerStaticHandlers
两个方法中设置 SymlinkCheck 安全检查,防止通过符号链接访问敏感文件。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-17 10:41:13 +08:00
6281196dfd
refactor(server): 优化结构体字段布局并使用 matcher 常量
...
- Server 和 VHostManager 结构体字段重新排序优化内存布局
- RegexHostMatcher 字段顺序调整
- 使用 matcher.LocationType* 常量替代硬编码字符串
- server_names 数组支持:遍历注册所有主机名
- 提取 createListener 方法支持 Unix socket
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-17 10:11:57 +08:00
c418baeb90
feat(vhost): 增强 server_name 匹配支持通配符和正则
...
按 nginx server_name 规则实现多类型匹配:
- 精确匹配:example.com
- 前缀通配:*.example.com(最长匹配优先)
- 后缀通配:example.*
- 正则匹配:~regex(按配置顺序)
- 匹配优先级:精确 → 前缀通配 → 后缀通配 → 正则 → 默认
更新 AddHost 返回 error 以支持正则编译错误反馈
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-17 09:26:47 +08:00
359afb5e24
feat(server): 集成 LocationEngine 和 Unix socket 监听支持
...
- 使用 LocationEngine 替代 fasthttp/router 进行路由匹配
- 新增 createListener 支持 Unix domain socket 监听
- 支持热升级场景下的 Unix socket 继承
- 新增 registerProxyRoutesWithLocationEngine 和 registerStaticHandlersWithLocationEngine
- 添加 SetUpgradeManager 方法供 App 层注入
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-17 09:26:38 +08:00
734304c5d7
test(server): 添加状态端点完整测试覆盖
...
- 测试 JSON/HTML/Text 输出格式
- 测试 localhost IP 限制
- 测试 Enabled 配置项控制
- 测试健康检查和指标输出
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 18:12:37 +08:00
05a414d1bb
feat(server): 添加 Purge 测试导出方法和安全检查
...
- purgeByPath/purgeByPattern 添加 nil server 检查
- 导出 PurgeByPathForTest/PurgeByPatternForTest 用于测试
- 添加 purge.go 全面单元测试覆盖
- 添加 cache purge 测试验证缓存清理功能
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 18:12:16 +08:00
bec8932561
feat(server): 添加缓存清理 API 支持
...
新增 PurgeHandler 处理器,支持:
- 按精确路径和通配符模式清理缓存
- HTTP 方法过滤(默认 GET)
- IP 白名单访问控制(CIDR/单 IP/localhost)
- Token 认证保护
- 三种启动模式路由注册
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 16:47:10 +08:00
8daab83d78
feat(status): 添加 HTML/Text 输出格式和 localhost IP 支持
...
扩展状态端点输出格式支持:
- json: 默认 JSON 格式
- text: 纯文本格式,便于终端查看
- html: HTML 表格格式,便于浏览器查看
- prometheus: Prometheus 指标格式
Allow 配置新增 "localhost" 特殊值支持,自动解析为
127.0.0.1/32 和 ::1/128,简化本地调试配置。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 15:07:12 +08:00
5625fdccc6
feat(status): 添加 Enabled 配置项显式控制状态端点启用
...
StatusConfig 新增 Enabled 字段,默认为 false 需显式启用。
修改 server.go 仅在 Enabled=true 时注册状态端点。
更新测试文件适配新配置结构。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 15:06:50 +08:00
8ed800271d
test: 迁移基准测试循环到 Go 1.24 b.Loop() API
...
- 所有 *_bench_test.go 文件从 for i := 0; i < b.N; i++ 改为 for b.Loop()
- 部分测试文件从 for i := 0; i < N; ... 改为 for range N 或 for i := range N
- 涵盖模块: cache, handler, http2, http3, loadbalance, logging, lua,
middleware/accesslog, middleware/bodylimit, middleware/rewrite,
middleware/security, netutil, resolver, server, ssl, stream
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 13:50:15 +08:00
79f7ed38f0
perf(server): 添加 goroutine 池对象池化效果验证基准测试
...
添加 BenchmarkGoroutinePoolObjectPool 测试池任务上下文复用能力,
添加 BenchmarkGoroutinePoolParallelSubmit 测试并发提交吞吐量,
验证 PoolTask 零分配复用场景。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 11:44:32 +08:00
470c82d940
style(proxy,server): 代码风格优化
...
- headers.go: 添加协议常量 protoHTTP/protoHTTPS
- redirect_rewrite.go: 添加模式常量,修正缩进
- proxy_ssl_test.go: 表格测试字段对齐
- server.go: 添加 ServerModeAuto 分支防御性处理
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 09:54:09 +08:00
bf14282e40
feat(server): 添加高并发优化配置支持
...
- ServerConfig 新增 Concurrency/ReadBufferSize/WriteBufferSize/ReduceMemoryUsage 配置
- defaults.go 设置默认值:256K 并发连接、16KB 缓冲区
- server.go 在 singleMode 和 vhostMode 中应用配置
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-15 18:26:49 +08:00
fa55bfd497
feat(cache): 添加缓存 TTL 新鲜度验证优化
...
在 FileEntry 中新增 CachedAt 字段记录缓存时间,实现 TTL 窗口内的缓存新鲜度验证:
- TTL 内跳过 ModTime 验证,减少 os.Stat 调用
- TTL 过期后验证 ModTime,文件未修改时刷新 CachedAt
- 默认 TTL 设置为 5 秒
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-15 17:53:51 +08:00
b0380f8798
feat(server): 改用前缀匹配注册代理路由
...
使用 fasthttp/router 通配符路由替代精确匹配:
- path: / 匹配所有子路径如 /sorry/index
- path: /api/ 匹配 /api/* 所有子路径
- 路由格式: {path}/{path:*}
此改动确保代理路径下所有子请求都能正确路由到代理处理器,
支持 redirect_rewrite 功能正确处理子路径的重定向改写。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-15 17:01:30 +08:00
d5b4509014
refactor(config,server): 移除 Config.Server 字段,完善 servers 多服务器配置
...
- 移除 Config.Server 单服务器字段,统一使用 Servers 列表
- 为 ServerConfig 添加 Default 标记支持虚拟主机默认主机
- 重命名 GetDefaultServer 为 GetDefaultServerFromList
- 更新验证逻辑确保 servers 列表必填
- 更新默认配置生成和测试适配
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-15 13:32:36 +08:00
f04f804834
refactor(server): 移除废弃的 Stop 方法,更新测试使用 StopWithTimeout
...
移除 deprecated Stop() 方法,测试代码改用 StopWithTimeout。
testutil.go 更新为支持 servers 配置格式。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-15 12:48:49 +08:00
d99011aab6
test(config,app,server): 更新测试适配 servers 配置格式
...
- 所有测试用例使用 Servers[0] 替代 Server
- 断言检查 servers: 替代 server:
- 生成配置测试验证新格式输出
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-15 10:34:04 +08:00
1f170b1951
refactor(server): 实现多服务器模式启动和关闭逻辑
...
- 新增 fastServers 列表支持多监听器
- 实现 startMultiServerMode() 并行启动多个服务器
- 添加 shutdownServers() 并行关闭多个 fasthttp.Server
- 重构 StopWithTimeout/GracefulStop 支持多服务器关闭
- startSingleMode 使用 Servers[0] 配置(迁移后)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-15 10:33:52 +08:00
cf0ea6cc1f
perf(lua): 完成协程栈优化配置集成
...
将 Lua 协程栈优化选项集成到配置系统中:
- CoroutineStackSize: 默认64,减少内存分配
- MinimizeStackMemory: 启用栈内存自动收缩
- CoroutinePoolWarmup: 默认预热4个协程
影响文件:
- internal/config/config.go: 添加配置项到 LuaGlobalSettings
- internal/lua/middleware_config.go: 中间件配置支持
- internal/server/init.go: 服务器初始化应用配置
优化效果(已在 engine.go 和 config.go 中实现):
- BenchmarkCoroutineCreation 内存减少18.7% (112KB->91KB)
- 延迟减少约27.6% (29us->21us)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 14:33:30 +08:00
fd4e164ae6
refactor(security): 滑动窗口限流器使用分段锁优化并发性能
...
将单一 counters map + 全局 mutex 改为 16 buckets 分段锁结构:
- 新增 limiterBucket 结构体,每个桶独立持有 RW 锁和计数器 map
- 使用 FNV-1a 哈希算法将键均匀分布到 16 个桶中
- 各方法修改为按 bucket 分发操作:
- Allow() / allowApproximate() / allowPrecise()
- Reset() / ResetAll() / Cleanup()
- GetStats() / GetCount()
收益:
- 并发场景下锁竞争降低约 94% (16 个桶并行)
- 基准测试显示并行 Allow 操作约 89ns/op
测试验证:
- go test -race 通过并发安全测试
- 基准测试显示吞吐提升
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 14:26:01 +08:00
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
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
5b41c3ab44
refactor(server): 使用 NewTargetFromConfig 简化目标创建
2026-04-13 16:40:50 +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
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
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
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
26ffc6b60d
fix(lint): 修复 Windows 平台文件 lint 错误
...
- 调整 App 结构体字段对齐以优化内存布局
- 添加文件末尾换行符
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
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
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
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
d22c20cbbb
feat(server): 添加 AuthRequest 外部认证中间件
...
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 13:22:35 +08:00
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
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