Merge remote-tracking branch 'origin/Alpha' into Alpha
# Conflicts: # component/sniffer/http_sniffer.go
This commit is contained in:
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user