cleanup: Drop ExtractPort ExtractHost, use ExtractHostAndPort instead
This commit is contained in:
parent
f0fae0c756
commit
0d553a9fa7
|
@ -143,25 +143,6 @@ func StringStripSpaces(str string) string {
|
|||
}, str)
|
||||
}
|
||||
|
||||
func ExtractPort(str string, defaultPort int) int {
|
||||
port := defaultPort
|
||||
if idx := strings.LastIndex(str, ":"); idx >= 0 && idx < len(str)-1 {
|
||||
if portX, err := strconv.Atoi(str[idx+1:]); err == nil {
|
||||
port = portX
|
||||
}
|
||||
}
|
||||
return port
|
||||
}
|
||||
|
||||
func ExtractHost(str string) string {
|
||||
if idx := strings.LastIndex(str, ":"); idx >= 0 && idx < len(str)-1 {
|
||||
if _, err := strconv.Atoi(str[idx+1:]); err == nil {
|
||||
str = str[:idx]
|
||||
}
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
func ExtractHostAndPort(str string, defaultPort int) (host string, port int) {
|
||||
host, port = str, defaultPort
|
||||
if idx := strings.LastIndex(str, ":"); idx >= 0 && idx < len(str)-1 {
|
||||
|
|
|
@ -502,7 +502,8 @@ func (config *Config) printRegisteredServers(proxy *Proxy, jsonOutput bool) {
|
|||
var summary []ServerSummary
|
||||
for _, registeredServer := range proxy.registeredServers {
|
||||
addrStr, port := registeredServer.stamp.ServerAddrStr, stamps.DefaultPort
|
||||
port = ExtractPort(addrStr, port)
|
||||
var hostAddr string
|
||||
hostAddr, port = ExtractHostAndPort(addrStr, port)
|
||||
addrs := make([]string, 0)
|
||||
if registeredServer.stamp.Proto == stamps.StampProtoTypeDoH && len(registeredServer.stamp.ProviderName) > 0 {
|
||||
providerName := registeredServer.stamp.ProviderName
|
||||
|
@ -511,7 +512,7 @@ func (config *Config) printRegisteredServers(proxy *Proxy, jsonOutput bool) {
|
|||
addrs = append(addrs, host)
|
||||
}
|
||||
if len(addrStr) > 0 {
|
||||
addrs = append(addrs, ExtractHost(addrStr))
|
||||
addrs = append(addrs, hostAddr)
|
||||
}
|
||||
serverSummary := ServerSummary{
|
||||
Name: registeredServer.name,
|
||||
|
|
|
@ -223,7 +223,7 @@ func (xTransport *XTransport) Fetch(method string, url *url.URL, accept string,
|
|||
req.Body = bc
|
||||
}
|
||||
var err error
|
||||
host := ExtractHost(url.Host)
|
||||
host, _ := ExtractHostAndPort(url.Host, 0)
|
||||
if xTransport.proxyDialer == nil && strings.HasSuffix(host, ".onion") {
|
||||
return nil, 0, errors.New("Onion service is not reachable without Tor")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue