From dde83d5a7c86517b6ea70b2f66029d5837851ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveirinha?= Date: Fri, 28 Oct 2022 15:48:10 +0100 Subject: [PATCH] TUN-6898: Refactor addPortIfMissing --- ingress/origin_service.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/ingress/origin_service.go b/ingress/origin_service.go index 5aaa26be..85fd29cd 100644 --- a/ingress/origin_service.go +++ b/ingress/origin_service.go @@ -9,7 +9,7 @@ import ( "net" "net/http" "net/url" - "strings" + "strconv" "time" "github.com/pkg/errors" @@ -158,13 +158,8 @@ func newSocksProxyOverWSService(accessPolicy *ipaccess.Policy) *socksProxyOverWS func addPortIfMissing(uri *url.URL, port int) { 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() == "" { - uri.Host = fmt.Sprintf("%s:%d", hostname, port) + uri.Host = net.JoinHostPort(hostname, strconv.FormatInt(int64(port), 10)) } }