From 6b6921f090ce3d0b4f89f4602fce9018fb0fb98d Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Tue, 16 Aug 2022 22:59:23 +0800 Subject: [PATCH] fix: http sniffer skip ip --- component/sniffer/http_sniffer.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/component/sniffer/http_sniffer.go b/component/sniffer/http_sniffer.go index 97ae607b..55385216 100644 --- a/component/sniffer/http_sniffer.go +++ b/component/sniffer/http_sniffer.go @@ -3,6 +3,7 @@ package sniffer import ( "bytes" "errors" + "fmt" C "github.com/Dreamacro/clash/constant" "net" "strings" @@ -88,7 +89,11 @@ func SniffHTTP(b []byte) (*string, error) { host, _, err := net.SplitHostPort(rawHost) if err != nil { if addrError, ok := err.(*net.AddrError); ok && strings.Contains(addrError.Err, "missing port") { - host = rawHost + if host, _, err = net.SplitHostPort(net.JoinHostPort(rawHost, "80")); err == nil { + if net.ParseIP(host) != nil { + return nil, fmt.Errorf("host is ip") + } + } } else { return nil, err }