112 Commits

Author SHA1 Message Date
xfy
4d608c4284 refactor(middleware): 提取限流 key 解析函数
- 新增 parseKeyFunc() 统一处理 key type 解析逻辑
- 消除重复代码,提高可维护性

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 11:20:43 +08:00
xfy
a965040eff refactor(handler): 提取平台字符串为常量
- 使用 platformLinux 常量替代硬编码字符串 "linux"

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 11:20:35 +08:00
xfy
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
xfy
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
xfy
616762e840 refactor(netutil): 提取通用主机名处理函数
- 新增 StripPort() 函数用于移除主机名中的端口
- 新增 HasPort() 函数用于检测主机名是否包含端口
- 替代 vhost 和 ssl 模块中的内联端口处理逻辑

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 11:20:10 +08:00
xfy
4e826925ac refactor: 适配核心模块类型重命名
适配 variable.NewContext/ReleaseContext
适配 resolver.DNSCacheEntry
适配 logging/formatJSON 常量

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:41:07 +08:00
xfy
2af3176507 refactor(middleware): 适配变量系统和 resolver 重命名
适配 variable.NewContext/ReleaseContext
适配 resolver.DNSCacheEntry

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:57 +08:00
xfy
ac8e89c492 refactor(http3): 适配 resolver.DNSCacheEntry 重命名
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:57 +08:00
xfy
239635301c refactor(http2): 适配变量系统和 resolver 重命名
适配 variable.NewContext/ReleaseContext
适配 resolver.DNSCacheEntry

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:57 +08:00
xfy
d89e55481c refactor(ssl): 适配 resolver.DNSCacheEntry 重命名
适配 resolver 模块类型重命名

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:48 +08:00
xfy
7950f17da5 refactor(server): 适配变量系统重命名
适配 variable.NewContext/ReleaseContext 重命名

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:47 +08:00
xfy
4c12703334 style(loadbalance): 使用自增运算符替代显式加法
totalWeight += 1 → totalWeight++

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:47 +08:00
xfy
649a6ed23f refactor(security): 重命名 HeadersMiddleware 移除冗余前缀
SecurityHeadersMiddleware → HeadersMiddleware
NewSecurityHeaders → NewHeaders
NewSecurityHeadersWithHSTS → NewHeadersWithHSTS

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:38 +08:00
xfy
3e153f5fe1 refactor(logging): 提取命名常量并适配变量系统重命名
提取 formatJSON 常量替代硬编码 "json"
适配 variable.NewContext/ReleaseContext 重命名

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:38 +08:00
xfy
1ce84ce9c5 refactor(proxy): 提取命名常量并适配变量系统重命名
提取硬编码字符串为命名常量:
- upstreamCache = "CACHE"
- protoHTTPS = "https"
ProxyWebSocket → WebSocket
适配 variable.Context 重命名

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:37 +08:00
xfy
b28ad378fa refactor(resolver): 重命名核心类型移除冗余前缀
ResolverStats → Stats
dnsCacheEntry → DNSCacheEntry (导出以符合 Go 命名规范)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:26 +08:00
xfy
4e535deb80 refactor(stream): 重命名 SSL 管理器类型移除冗余前缀
StreamSSLManager → SSLManager
StreamProxySSLManager → ProxySSLManager

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:26 +08:00
xfy
53319bbdd3 docs(variable): 更新 AGENTS.md 反映类型重命名
VariableContext → Context 相关文档同步更新

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:26 +08:00
xfy
0731dc46e4 refactor(variable): 重命名核心类型移除冗余前缀
VariableContext → Context
VariableStore → Store
ReleaseVariableContext → ReleaseContext (别名保留向后兼容)
提取硬编码字符串为命名常量 sslProtocolNone

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:40:17 +08:00
xfy
ce43d5c1d6 feat(cache): 新增缓存清理 API
支持通过 HTTP API 主动清理代理缓存,提供精确路径和通配符模式清理。
包含 IP 白名单和 Token 认证支持。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 17:58:18 +08:00
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
83b2a35715 feat(config): 完善 Resolver/SSL 默认值及 YAML 输出
- 添加 Resolver/SessionTickets/ClientVerify 默认配置
- GenerateConfigYAML 输出改为非注释格式
- 新增 Resolver、SSL 默认值、YAML 可加载性测试

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 14:44:01 +08:00
xfy
909bccc1eb refactor(http2): 使用 textproto.CanonicalMIMEHeaderKey 替代手动实现
使用标准库 net/textproto 提供的规范化函数,确保 HTTP 头键
按照 RFC 7230 规范正确处理,包括 MIME 头的特殊大小写规则。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 13:35:29 +08:00
xfy
392d0b3449 docs: 新增模块 AGENTS.md 文档,更新目录索引
- 新增 http2、integration、resolver、variable 模块 AGENTS.md
- 更新 internal/AGENTS.md 目录表,补充新模块条目
- 更新 docs/prompts.md 添加 generate-config 缺失项分析提示
- 同步更新日期戳至 2026-04-09

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 13:35:29 +08:00
xfy
a298ca7254 feat(config): 完善 GenerateConfigYAML HTTP/2 和认证配置示例输出
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 13:25:47 +08:00
xfy
e03546a580 feat(config): 完善 GenerateConfigYAML 配置示例输出
新增 Session Tickets、mTLS 客户端验证、auth_request 外部认证、
TCP SSL、DNS resolver 及全局变量配置的 YAML 示例生成
2026-04-09 13:10:15 +08:00
xfy
4d5dda5b69 style(variable): 添加文件末尾换行符 2026-04-09 12:19:22 +08:00
xfy
84c26c61ca style(benchmark): 修复代码格式和忽略无用错误返回值 2026-04-09 12:19:08 +08:00
xfy
668ecde6db feat(variable): 新增全局变量支持,自动注入请求上下文 2026-04-09 12:18:56 +08:00
xfy
412bfebdd8 feat(http2): 新增 HTTP/2 支持,集成到服务器和应用 2026-04-09 12:18:52 +08:00
xfy
25bdba4e01 test(benchmark): 新增组件级基准测试套件
- 新增 benchmark_context.go 标准化测试上下文构造器
- 新增静态文件处理器基准测试(缓存命中/未命中、try_files)
- 新增访问日志中间件基准测试
- 新增压缩中间件基准测试(gzip/brotli、Pool 复用)
- 新增限流器基准测试(令牌桶、滑动窗口、多客户端并发)
- 新增变量展开基准测试(模板展开、Pool 操作)
2026-04-08 18:25:38 +08:00
xfy
0602796ee1 feat(ratelimit): 新增后台自动清理和优雅关闭
- RateLimiter 启动时自动开启后台清理 goroutine
- 新增 StopCleanup 方法优雅关闭清理 goroutine
- 新增 AutoCleanup 和 StopCleanup 测试

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-08 15:03:10 +08:00
xfy
4de32812f2 perf(loadbalance): 预计算一致性哈希虚拟节点哈希值
- Target 结构新增 VirtualHashes 字段存储预计算哈希
- 新增 PrecomputeHashes 方法在初始化时计算虚拟节点哈希
- SelectExcludingByKey 使用预计算哈希避免运行时重复计算
- 新增 SelectExcludingByKey 测试和基准测试

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-08 15:03:10 +08:00
xfy
214ea4e9a6 perf(cache,proxy): 使用 uint64 哈希键优化代理缓存性能
- ProxyCache 的 entries 和 pending map 从 string 改为 uint64 键
- 新增 buildCacheKeyHash 使用 FNV-64a 计算哈希(零分配)
- 增加原始键碰撞验证,防止哈希冲突误匹配
- 更新相关测试和基准测试

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-08 15:03:10 +08:00
xfy
49d33f8b0c feat(middleware/security): 新增 auth_request 外部认证中间件
- 支持将认证委托给外部服务,根据响应状态码决定请求是否继续
- 配置 URI、Method、Timeout 和自定义 Headers
- 支持 $request_uri 等变量在 Headers 中使用

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-08 14:37:29 +08:00
xfy
84d67c8570 feat(handler/static): 新增 alias 指令支持路径别名
- NewStaticHandlerWithAlias 创建带 alias 的静态文件处理器
- alias 与 root 互斥,支持路径替换而非附加
- 新增测试覆盖 alias 路径映射逻辑

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-08 14:37:20 +08:00
xfy
d48caf5183 feat(proxy): 新增代理响应临时文件处理,保护内存
- TempFileHandler 检测响应大小,超过阈值写入临时文件
- TempFileCleaner 定期清理过期临时文件
- 避免 SSR 攻击和内存溢出风险

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-08 14:37:13 +08:00
xfy
1a9059b1ff feat(stream): 新增 TCP/UDP Stream SSL/TLS 支持
- StreamSSLManager 管理服务端 TLS 终端和客户端 TLS 连接
- 支持证书加载、mTLS 客户端验证
- 并发安全的证书配置管理

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-08 14:37:02 +08:00
xfy
b7de258f4e feat(variable): 新增 SSL 客户端证书变量支持
- 新增 ssl_client_verify、ssl_client_serial、ssl_client_subject 等变量
- 支持从 TLS 连接状态提取客户端证书信息
- 用于日志记录和访问控制决策

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-08 14:36:53 +08:00
xfy
9d49349ee1 feat(ssl,config): 新增 Session Tickets 和 mTLS 客户端证书验证
- SessionTicketsConfig 支持 TLS 1.3 会话恢复,密钥轮换和持久化
- ClientVerifyConfig 支持双向 TLS 认证,CA 证书池和 CRL
- TLSManager 集成 SessionTicketManager 和 ClientVerifier
- 新增完整测试覆盖密钥轮换和客户端验证逻辑

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-08 14:36:47 +08:00
xfy
61455412eb feat(variable,proxy): 新增上游变量支持,集成到代理请求处理
- 新增 upstream_addr、upstream_status、upstream_response_time 等变量
- 新增 UpstreamTiming 结构体捕获连接、首字节、响应时间
- Proxy.ServeHTTP 集成变量上下文,记录上游时间
- 新增测试覆盖上游变量和计时功能

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-08 14:36:37 +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
5a6f4d351f feat(resolver): 新增 DNS 解析器支持
新增 internal/resolver 包,提供动态 DNS 解析功能:
- Resolver 类型支持配置多个 DNS 服务器
- 内置缓存支持 TTL 和最大条目数限制
- 统计信息追踪查询次数和缓存命中率

配置层面:
- ResolverConfig 支持 addresses/valid/timeout/ipv4/ipv6/cache_size
- 添加配置验证逻辑

Target 增强:
- 新增 hostname/resolvedIPs 字段支持 IP 缓存
- NeedsResolve 方法判断是否需要重新解析
- NewTargetFromConfig 工厂函数

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-08 11:36:49 +08:00
xfy
c95f474539 feat(variable): 新增变量系统支持
新增 internal/variable 包,提供 Nginx 风格的变量展开功能:
- 支持 $remote_addr、$host、$uri、$args 等 30+ 内置变量
- 使用 sync.Pool 优化 VariableContext 分配
- 支持 set_response_info 存储响应状态信息

添加 github.com/google/uuid 依赖用于请求 ID 生成。

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
238fa20e41 docs(config): 在默认配置生成中添加已实现功能的注释示例
新增 client_max_body_size、try_files、next_upstream、error_page 等功能的配置注释

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-08 10:35:45 +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
3758f410ff style(benchmark): 修复文件末尾换行符
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-08 09:58:11 +08:00