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
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
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
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
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
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
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
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
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
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
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
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
d22c20cbbb
feat(server): 添加 AuthRequest 外部认证中间件
...
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 13:22:35 +08:00
7950f17da5
refactor(server): 适配变量系统重命名
...
适配 variable.NewContext/ReleaseContext 重命名
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:47 +08:00
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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