lolly/internal/http2/AGENTS.md
xfy 2122067efb docs: 更新 AGENTS.md 文档,添加新模块说明
- 更新所有 AGENTS.md 时间戳至 2026-04-24
- 添加 converter、e2e、testutil 模块文档
- 更新 README.md:nginx 配置导入、stale 缓存功能说明
- 更新项目统计:132 Go 文件,157 测试文件

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-24 18:24:31 +08:00

50 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!-- Parent: ../AGENTS.md -->
<!-- Generated: 2026-04-09 | Updated: 2026-04-24 -->
# http2
## Purpose
HTTP/2 协议支持模块,基于 golang.org/x/net/http2 实现,提供 ALPN 协议协商、与 fasthttp handler 的集成、优雅关闭支持。
## Key Files
| File | Description |
|------|-------------|
| `server.go` | HTTP/2 服务器核心Server 结构、NewServer、Start、GracefulStop |
| `adapter.go` | fasthttp 适配层FastHTTPHandlerAdapter、零拷贝头部转换、流式请求体处理 |
| `server_test.go` | 服务器测试:创建、启动、关闭测试 |
| `adapter_test.go` | 适配器测试:头部转换、请求体处理测试 |
| `integration_test.go` | 集成测试:端到端 HTTP/2 请求处理 |
| `integration_tls_test.go` | TLS 集成测试HTTPS 连接测试 |
## For AI Agents
### Working In This Directory
- HTTP/2 服务器使用标准库 http.Handler 接口
- 通过适配层转换 fasthttp.RequestHandler → http.Handler
- 需要 TLS 配置进行 ALPN 协商h2 协议标识)
- 使用 sync.Pool 复用缓冲区实现零拷贝优化
- 预估每请求 5-10µs 适配开销
### Testing Requirements
- 运行测试:`go test ./internal/http2/...`
- 测试需要 TLS 配置(部分测试)
- 集成测试验证完整请求流程
### Common Patterns
- NewServer(cfg, handler, tlsConfig) 创建服务器
- Start() 在现有 TCP 监听器上启动
- GracefulStop() 优雅关闭等待请求完成
- FastHTTPHandlerAdapter.ServeHTTP 实现标准库接口
## Dependencies
### Internal
- `../config/` - HTTP2Config 配置结构体
- `../logging/` - 日志模块
### External
- `golang.org/x/net/http2` - HTTP/2 协议实现
- `github.com/valyala/fasthttp` - fasthttp handler 类型
<!-- MANUAL: -->