// httpprobe 包示例:按报文首部字节识别流量是 HTTP 还是 HTTPS(常用于网关/代理分流) package main import ( "fmt" "git.zeroonesoft.cn/golib/zogo/httpprobe" ) func main() { // HTTP 请求报文(以请求方法开头) httpData := []byte("GET /index.html HTTP/1.1\r\nHost: localhost\r\n\r\n") fmt.Println("IsHttp(HTTP报文):", httpprobe.IsHttp(httpData)) // TLS 握手报文(首字节 0x16 0x03) httpsData := make([]byte, 32) httpsData[0] = 0x16 httpsData[1] = 0x03 httpsData[3] = 0x01 copy(httpsData[8:], "http") // ClientHello 的 SNI 中会出现 host 字符 fmt.Println("IsHttps(TLS报文):", httpprobe.IsHttps(httpsData)) // 普通数据两者都不是 fmt.Println("IsHttp(普通数据):", httpprobe.IsHttp([]byte("hello world"))) fmt.Println("IsHttps(普通数据):", httpprobe.IsHttps([]byte("hello world"))) }