Browse code

Use default port to proxy to backend

Jordan Liggitt authored on 2015/05/05 02:17:12
Showing 1 changed files
... ...
@@ -13,6 +13,8 @@ import (
13 13
 	"strings"
14 14
 
15 15
 	kclient "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
16
+	"github.com/GoogleCloudPlatform/kubernetes/third_party/golang/netutil"
17
+
16 18
 	"github.com/golang/glog"
17 19
 )
18 20
 
... ...
@@ -135,21 +137,23 @@ func (p *UpgradeAwareSingleHostReverseProxy) ServeHTTP(w http.ResponseWriter, re
135 135
 }
136 136
 
137 137
 func (p *UpgradeAwareSingleHostReverseProxy) dialBackend(req *http.Request) (net.Conn, error) {
138
+	dialAddr := netutil.CanonicalAddr(req.URL)
139
+
138 140
 	switch p.backendAddr.Scheme {
139 141
 	case "http":
140
-		return net.Dial("tcp", req.URL.Host)
142
+		return net.Dial("tcp", dialAddr)
141 143
 	case "https":
142 144
 		tlsConfig, err := kclient.TLSConfigFor(p.clientConfig)
143 145
 		if err != nil {
144 146
 			return nil, err
145 147
 		}
146
-		tlsConn, err := tls.Dial("tcp", req.URL.Host, tlsConfig)
148
+		tlsConn, err := tls.Dial("tcp", dialAddr, tlsConfig)
147 149
 		if err != nil {
148 150
 			return nil, err
149 151
 		}
150
-		hostToVerify := req.URL.Host
151
-		if index := strings.Index(hostToVerify, ":"); index > -1 {
152
-			hostToVerify = hostToVerify[0:index]
152
+		hostToVerify, _, err := net.SplitHostPort(dialAddr)
153
+		if err != nil {
154
+			return nil, err
153 155
 		}
154 156
 		err = tlsConn.VerifyHostname(hostToVerify)
155 157
 		return tlsConn, err