Files
4566704 caa65209ac feat(httpprobe): go-hua/http 迁入并更名 httpprobe(HTTP/HTTPS 协议探测)
- 原包名 http 与标准库 net/http 严重混淆, 实为按首部字节探测协议,
  更名 httpprobe; spmux 将基于此做单端口分流, 附测试、例程与 README
2026-09-20 12:25:36 +08:00

28 lines
1.0 KiB
Markdown
Raw Permalink 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.
# httpprobe
按报文首部字节识别流量是 HTTP 还是 HTTPS(TLS ClientHello),常用于网关/代理
在同一端口上做协议分流(本仓库 `spmux` 即基于此实现)。
> 迁移自 go-hua/http 并更名:原包名 `http` 与标准库 `net/http` 严重混淆,
> 实际功能是"协议探测"而非 HTTP 客户端,故更名 `httpprobe`。
## 用法
```go
import "git.zeroonesoft.cn/golib/zogo/httpprobe"
httpprobe.IsHttp([]byte("GET /index.html HTTP/1.1\r\nHost: a.com\r\n\r\n")) // true
httpprobe.IsHttp([]byte("hello world")) // false
// TLS ClientHello(首字节 0x16 0x03)
httpprobe.IsHttps(clientHello) // true
```
完整可运行例程:[examples/httpprobe/main.go](../examples/httpprobe/main.go)
## 注意
- 识别基于首部字节的启发式规则:HTTP 按合法请求方法前缀判断,HTTPS 按
TLS record 头(0x16 0x03)判断,均为工程实践口径而非完整协议解析。
- 迁移自 go-hua 的消费方:`http.IsHttp(...)` → `httpprobe.IsHttp(...)`。