TUN-6898: Refactor addPortIfMissing
This commit is contained in:
parent
e14238224d
commit
dde83d5a7c
|
@ -9,7 +9,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -158,13 +158,8 @@ func newSocksProxyOverWSService(accessPolicy *ipaccess.Policy) *socksProxyOverWS
|
||||||
func addPortIfMissing(uri *url.URL, port int) {
|
func addPortIfMissing(uri *url.URL, port int) {
|
||||||
hostname := uri.Hostname()
|
hostname := uri.Hostname()
|
||||||
|
|
||||||
// check if it is an IPv6 address and wrap it with brackets
|
|
||||||
if ip := net.ParseIP(hostname); ip != nil && strings.Count(hostname, ":") > 0 {
|
|
||||||
hostname = fmt.Sprintf("[%s]", hostname)
|
|
||||||
}
|
|
||||||
|
|
||||||
if uri.Port() == "" {
|
if uri.Port() == "" {
|
||||||
uri.Host = fmt.Sprintf("%s:%d", hostname, port)
|
uri.Host = net.JoinHostPort(hostname, strconv.FormatInt(int64(port), 10))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue