33 Commits

Author SHA1 Message Date
xfy
612208616c feat(status): 支持 Prometheus 格式输出
新增 Prometheus 格式的状态指标输出,用于监控系统集成。
包含连接数、请求数、缓存、Pool、Upstream、SSL、限流等指标。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 17:51:28 +08:00
xfy
b72394eb3b style(handler,server): 格式化测试代码结构体字段对齐
- 对齐 errorpage_test.go、static_test.go、pprof_test.go 中的结构体字段
- 纯代码格式化,无逻辑变更

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-08 13:30:00 +08:00
xfy
3711b12fad docs(server/pprof): 添加详细函数文档注释,修复注释错字
- 为 pprof.go 和 pprof_impl.go 的所有公开函数添加文档注释
- 包含参数说明、返回值描述、使用示例和注意事项
- 修复注释错字"厉止"→"停止"
- 补充包级文档说明核心功能和用途

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-08 13:30:00 +08:00
xfy
9495a548e6 feat(proxy,server,logging): 集成变量系统和 DNS 解析器
变量系统集成:
- logging: 访问日志使用 variable 包展开模板
- rewrite: 重写规则支持变量展开
- proxy: 请求/响应头设置支持变量展开

DNS 解析器集成:
- app: 创建并启用 Resolver
- server: SetResolver/GetResolver 方法传递给 proxy
- proxy: SetResolver/Start 方法,后台 DNS 刷新协程
- proxy_dns.go: DNS 刷新逻辑和 IP 直连支持

新增集成测试:
- internal/integration/variable_test.go
- internal/integration/resolver_test.go

文档更新:
- docs/config-reference.md 配置参考文档

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-08 11:36:49 +08:00
xfy
b6f8894d78 test(handler,middleware,server): 新增 try_files、错误页面、pprof 单元测试
- static_test.go: 新增 try_files 配置解析、占位符解析、SPA 场景测试
- errorpage_test.go: 新增错误页面管理器完整测试覆盖
- errorintercept_test.go: 新增错误拦截中间件功能测试
- pprof_test.go: 新增 pprof 性能分析端点测试

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-08 11:15:39 +08:00
xfy
d482e44bec refactor(server/pprof): 简化 switch 语句并移除未使用变量
- 将 switch 语句改为更简洁的 case 匹配形式
- 移除未使用的 cpuProfileWriter 变量
- 忽略 Flush/WriteTo 等无关的错误返回值

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-08 09:58:11 +08:00
xfy
766e9255fa feat(config,server,makefile): 新增 pprof 性能分析端点支持
- 新增 PprofConfig 配置结构,支持路径和 IP 访问控制
- 实现 PprofHandler 处理器,提供 CPU/heap/goroutine/block/mutex profile
- Makefile 新增 build-perf、build-pgo、pgo-collect 目标
- 支持 PGO (Profile-Guided Optimization) 构建

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-07 18:21:03 +08:00
xfy
23f5c08614 feat(handler,server): 静态文件新增 try_files 配置,集成新增中间件
- StaticHandler 支持 try_files 配置,用于 SPA 部署回退
- 支持 $uri 和 $uri/ 占位符解析
- Server 集成 bodylimit 中间件(全局和路径级别配置)
- Server 集成 errorintercept 中间件(错误页面拦截)
- Server 预加载错误页面到内存

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 17:50:38 +08:00
xfy
83e1fe38ba feat(config,handler,server): 支持多静态目录配置,新增路径前缀匹配
- Static 配置从单对象改为数组,支持多个静态目录
- StaticConfig 新增 Path 字段用于路径前缀匹配
- 添加 validateStatics 和 validatePathConflicts 验证函数
- 删除 config.example.yaml 示例文件(配置可通过 --generate 生成)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-07 16:26:55 +08:00
xfy
f2352ab9cc docs(config,stream,logging,handler,proxy,cache,server,ssl,middleware): 为核心模块添加详细 GoDoc 文档注释
- config: 为 Config 和所有子配置结构添加完整文档,包含使用示例和注意事项
- stream: 为负载均衡器和服务器添加详细的参数、返回值和功能说明
- logging: 为日志格式化和输出函数添加文档,说明支持的变量替换
- handler: 为路由器、静态文件和 sendfile 处理器添加文档
- proxy: 为健康检查器和代理功能添加完整文档
- cache/server/ssl/middleware: 补充相关模块的文档注释
- config.example.yaml: 添加可信代理配置、加密套件示例,更新压缩级别说明

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-07 15:36:09 +08:00
xfy
3cc2dc7625 style(netutil,server,test): 修复代码格式问题,更新文档
- 修复 server.go 缩进问题
- 添加文件末尾换行符
- 格式化测试文件表格对齐
- 更新 update-prompts.md 添加新任务

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 11:38:54 +08:00
xfy
77fdb11b06 test(server): 完善 server 模块测试覆盖率
覆盖率从 44.2% 提升至 45.8%,新增测试:
- TestPoolWrapHandler: 协程池处理器包装测试
- TestPoolWrapHandler_WhenStopped: 池停止时包装测试
- TestServer_Proxies: 代理管理测试
- TestServer_Running: 运行状态测试
- TestServer_StopWithNilFastServer: 无服务器停止测试
- TestServer_GracefulStopWithNilFastServer: 无服务器优雅停止测试
- TestServer_GetProxyCacheStats: 代理缓存统计测试
- TestServer_BuildMiddlewareChain_EmptyConfig: 空配置中间件链测试
- TestServer_TrackStats_EmptyBody: 空响应体统计测试

注:Start/startSingleMode 等启动函数适合集成测试

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-03 18:33:10 +08:00
xfy
7a98a0b044 refactor: 抽取网络工具函数到 netutil 包,移除冗余代码
- 新增 internal/netutil 包,统一 IP 提取和 URL 解析函数
- proxy/websocket/middleware 使用 netutil 替代重复实现
- 移除 handler/sendfile 中未使用的 BufferPool 相关代码
- 移除 http3/adapter 中未使用的反向转换函数
- 提取 server.registerStaticHandler 函数改进代码结构
- 优化 access.go 锁范围,减少持锁时间

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 18:24:21 +08:00
xfy
cd2d1a8194 refactor: 优化字符串构建方式,统一测试错误处理风格
- 使用 fmt.Fprintf 替代冗余的 WriteString(fmt.Sprintf) 组合
- 测试中 nil 检查使用 t.Fatal 替代 t.Error 立即终止
- .gitignore 添加 html/ 目录忽略

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-03 17:49:11 +08:00
xfy
fc71cf4835 refactor(test): 统一测试文件错误处理风格
使用空白标识符忽略测试辅助函数中 Close、ReadFrom、Set 等返回值,
与主代码风格保持一致。

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 17:37:05 +08:00
xfy
96ed39e162 refactor(http3,handler,server,middleware): 改进错误处理与代码优化
- 使用 _ 忽略 Close、Write、Shutdown 等返回值
- compression 使用 switch-case 替代 if-else 链
- http3/adapter 使用 for-range 替代 VisitAll 遍历头部
- sendfile 添加 nolint 注释说明 buffer pool 设计决策
- defer 关闭文件使用 func() { _ = file.Close() } 确保执行

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 17:36:58 +08:00
xfy
92cd93d4c0 refactor: 代码改进与注释补充
- logging: 补充包文档说明
- pool: 修复 workers 计数器并发安全 (atomic 操作)
- stream: 完善注释与错误处理
- handler/static: 添加预压缩文件支持接口
- loadbalance: 补充算法注释
- vhost: 改进虚拟主机路由逻辑
- ssl: 优化证书加载注释
- main: 补充启动流程注释

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 16:57:59 +08:00
xfy
03b0df2c69 feat(proxy): 实现代理缓存功能与一致性哈希支持
- 新增缓存命中/过期/刷新逻辑
- 实现缓存锁防止缓存击穿 (stale-while-revalidate)
- 支持一致性哈希按 uri/ip/header 选择目标
- 新增 getProxyCacheStats 收集缓存统计
- 集成连接数限制中间件 (ConnLimiter)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 16:57:48 +08:00
xfy
d42844b2fa test(app,handler,server,http3): 补充单元测试覆盖率
- app: 添加信号处理、配置重载、日志重开测试
- handler/sendfile: 添加小文件、偏移量、错误情况测试
- server: 添加统计追踪、监听器、TLS配置测试
- http3: 新增 adapter 和 server 单元测试
- 格式修复: 末尾换行符、注释对齐
- 文档: AGENTS.md 添加 http3 模块说明

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 16:25:21 +08:00
xfy
ec916d882d feat(proxy,middleware,config): 集成配置与代码差异修复
- 集成一致性哈希负载均衡到 proxy.go,支持 hash_key 和 virtual_nodes 配置
- 集成滑动窗口限流算法到 ratelimit.go,支持 algorithm 选择
- 应用 Transport 连接池配置到 createHostClient
- 集成 HSTS 配置到安全头部中间件
- 补充 config.example.yaml 缺失配置(http3、gzip_static、sliding_window)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 16:08:45 +08:00
xfy
d6367a1c38 feat(http3,docs,middleware): 实现 Phase 9 HTTP/3 与性能优化扩展
- 新增 HTTP/3 (QUIC) 服务器支持,集成到 App 生命周期管理
- 新增 nginx 内置变量速查表文档
- 完善多篇 nginx 文档(代理、安全、流、限流、HTTP/2/3、核心事件)
- 新增一致性哈希负载均衡、gzip_static、滑动窗口限流中间件
- 扩展配置支持 HTTP/3 和日志格式选项

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 15:39:06 +08:00
xfy
a627d58832 test(server): 补充 buildMiddlewareChain 单元测试
- 新增访问日志、访问控制、限流中间件测试
- 新增重写、压缩、安全头中间件测试
- 新增全中间件组合测试
- 重命名 TestSetListeners 为 TestUpgradeSetListeners 避免命名冲突

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-03 15:15:37 +08:00
xfy
f894787a2b test(handler,server,proxy): 补充单元测试覆盖率
- sendfile_test.go: 新增 copyFile、platformSendfile、getSocketFd 测试
- upgrade_test.go: 新增监听器设置、PID文件处理、继承监听器测试
- websocket_test.go: 新增 WebSocket 桥接器、数据转发、连接关闭测试
- status_test.go: 新增 StatusHandler CIDR/IP访问控制、状态收集测试

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-03 15:02:51 +08:00
xfy
ac9153f09d fix(proxy,stream,server): Phase 8 问题修复与功能完善
- WebSocket 代理集成:handleWebSocket 现调用 ProxyWebSocket 实现
- 删除 UDP Stream 冗余代码:移除 udpListener 类型及相关测试
- 热升级监听器继承:改用 net.Listen + Serve 模式支持监听器传递
- 代码格式修复:注释格式调整、字段对齐、文件末尾换行符

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 14:28:00 +08:00
xfy
95030cd68a docs: 更新 AGENTS.md 文档
添加各模块的 AGENTS.md 文档文件,记录模块职责和代码结构

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 14:07:42 +08:00
xfy
80936ae66b feat(server,proxy,ssl,docs): 完成 Phase 7 功能完善
主要变更:
- WebSocket 代理支持 (internal/proxy/websocket.go)
- OCSP stapling 实现 (internal/ssl/ocsp.go)
- 监控状态端点 (internal/server/status.go)
- 新增 nginx 模块文档 (19-24)
- UDP 代理超时配置支持
- 多模块代码注释完善和功能增强

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-03 13:13:12 +08:00
xfy
aa64329ba2 feat(server,handler,proxy,app): 集成未使用的中间件和模块
- 集成 6 个安全/功能中间件到 server.go
- 集成 GoroutinePool 和 SendFile 零拷贝
- 集成 FileCache 和 ProxyCache 缓存模块
- 集成 Stream TCP/UDP 代理模块
- 添加 Stream 配置结构到 config.go

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-03 11:27:53 +08:00
xfy
6f3ecb0a9f feat(middleware,server): 实现访问日志中间件
- 新增 accesslog 中间件,记录请求方法、路径、状态码、响应大小和处理时间
- 集成到 Server 的 single 和 vhost 模式
- 支持 graceful shutdown 时关闭日志文件

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 10:54:53 +08:00
xfy
9d24263918 feat(stream,server,handler): 实现 Phase 6 性能优化和热升级
新增功能:
- stream 模块: 流式传输支持,优化大文件和实时数据传输
- Goroutine 池: 限制并发数量,减少调度开销
- 优雅升级: 零停机热升级,继承父进程监听器
- sendfile: 零拷贝文件传输,大文件直接从内核传输

重构改进:
- App 结构体封装,支持热升级和信号处理
- 配置结构字段对齐和代码清理
- 完善错误处理和日志记录

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 10:39:22 +08:00
xfy
e2c37e2bf8 feat(server,proxy,loadbalance): 集成反向代理和虚拟主机模式
- server: 集成反向代理路由,支持单服务器和虚拟主机两种模式
- loadbalance: 使用 atomic.Bool 替代 bool 实现并发安全的健康状态
- proxy: 适配 atomic.Bool,移除 HealthChecker 不必要的互斥锁
- config: 添加服务器超时配置字段,验证负载均衡算法
- 新增 algorithms.go 提供算法验证函数
- 新增 config.example.yaml 配置示例文件

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 09:26:20 +08:00
xfy
179aacac04 docs: 添加模块上下文文档 (AGENTS.md)
为各模块添加上下文文档,帮助 AI 助手理解代码结构:
- AGENTS.md: 项目根目录上下文
- docs/AGENTS.md: 文档目录说明
- internal/AGENTS.md: 内部包结构概览
- 各子模块 AGENTS.md: 模块特定上下文和约定

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-02 16:25:51 +08:00
xfy
413e418b37 test: 添加 handler/logging/middleware/server 模块单元测试
- internal/handler/static_test.go: 21 个测试用例覆盖静态文件服务和路径遍历安全
- internal/handler/router_test.go: 9 个测试用例覆盖路由注册和方法区分
- internal/logging/logging_test.go: 7 个测试用例覆盖日志级别解析
- internal/middleware/middleware_test.go: 4 个测试用例覆盖中间件链逆序包装
- internal/server/server_test.go: 5 个测试用例覆盖服务器创建和停止
- internal/server/vhost_test.go: 18 个测试用例覆盖虚拟主机路由

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-02 16:21:49 +08:00
xfy
b445bca96a feat(server): 实现基础 HTTP 服务器核心功能
使用 fasthttp 替代 net/http,实现 Phase 2 核心模块:
- HTTP 服务器:fasthttp.Server 配置超时和连接限制
- 路由系统:fasthttp/router 基于 radix tree 匹配
- 静态文件服务:安全检查、索引文件支持
- 日志系统:zerolog 结构化日志
- 中间件框架:链式组合接口
- 虚拟主机管理:按 Host 头选择处理器

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-02 15:23:54 +08:00