Skip to content

Commit 8f01cdc

Browse files
committed
Fix proxyURL method always returns wrong URL format for IPv4 addresses
Signed-off-by: Arming <[email protected]> Fix proxyURL method always returns wrong URL format for IPv4 addresses Signed-off-by: Arming <[email protected]>
1 parent 44e3a32 commit 8f01cdc

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

pkg/osutil/dns_darwin.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,20 @@ func DNSAddresses() ([]string, error) {
2828
}
2929

3030
func proxyURL(proxy string, port interface{}) string {
31-
if !strings.Contains(proxy, "://") {
31+
if strings.Contains(proxy, "://") {
32+
if portNumber, ok := port.(float64); ok && portNumber != 0 {
33+
proxy = fmt.Sprintf("%s:%.0f", proxy, portNumber)
34+
} else if portString, ok := port.(string); ok && portString != "" {
35+
proxy = fmt.Sprintf("%s:%s", proxy, portString)
36+
}
37+
} else {
38+
if portNumber, ok := port.(float64); ok && portNumber != 0 {
39+
proxy = net.JoinHostPort(proxy, fmt.Sprintf("%.0f", portNumber))
40+
} else if portString, ok := port.(string); ok && portString != "" {
41+
proxy = net.JoinHostPort(proxy, portString)
42+
}
3243
proxy = "http://" + proxy
3344
}
34-
if portNumber, ok := port.(float64); ok && portNumber != 0 {
35-
proxy = net.JoinHostPort(proxy, fmt.Sprintf("%.0f", portNumber))
36-
} else if portString, ok := port.(string); ok && portString != "" {
37-
proxy = net.JoinHostPort(proxy, portString)
38-
}
3945
return proxy
4046
}
4147

0 commit comments

Comments
 (0)