Merge remote-tracking branch 'origin/Alpha' into Alpha

# Conflicts:
#	component/sniffer/http_sniffer.go
This commit is contained in:
metacubex
2022-08-22 23:22:26 +08:00
6 changed files with 194 additions and 142 deletions

View File

@ -12,7 +12,6 @@ import (
CN "github.com/Dreamacro/clash/common/net"
"github.com/Dreamacro/clash/common/utils"
"github.com/Dreamacro/clash/component/resolver"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/log"
)
@ -84,8 +83,7 @@ func (sd *SnifferDispatcher) replaceDomain(metadata *C.Metadata, host string) {
metadata.AddrType = C.AtypDomainName
metadata.Host = host
metadata.DNSMode = C.DNSMapping
resolver.InsertHostByIP(metadata.DstIP, host)
metadata.DNSMode = C.DNSNormal
}
func (sd *SnifferDispatcher) Enable() bool {

View File

@ -89,17 +89,32 @@ 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") {
if host, _, err = net.SplitHostPort(net.JoinHostPort(rawHost, "80")); err == nil {
if net.ParseIP(host) != nil {
return nil, fmt.Errorf("host is ip")
}
}
return parseHost(rawHost)
} else {
return nil, err
}
}
if net.ParseIP(host) != nil {
return nil, fmt.Errorf("host is ip")
}
return &host, nil
}
}
return nil, ErrNoClue
}
func parseHost(host string) (*string, error) {
if strings.HasPrefix(host, "[") && strings.HasSuffix(host, "]") {
if net.ParseIP(host[1:len(host)-1]) != nil {
return nil, fmt.Errorf("host is ip")
}
}
if net.ParseIP(host) != nil {
return nil, fmt.Errorf("host is ip")
}
return &host, nil
}