Skip to content

Commit 1bdc0ed

Browse files
committed
strip port (e.g. :80) off the host routing
Signed-off-by: Ahmet Alp Balkan <[email protected]>
1 parent 91531d1 commit 1bdc0ed

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

runsd/proxy.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"context"
2020
"fmt"
2121
"io/ioutil"
22+
"net"
2223
"net/http"
2324
"net/http/httputil"
2425
"strings"
@@ -55,8 +56,13 @@ func (rp *reverseProxy) newReverseProxyHandler(tr http.RoundTripper) http.Handle
5556
Transport: transport,
5657
FlushInterval: -1, // to support grpc streaming responses
5758
Director: func(req *http.Request) {
58-
klog.V(5).Infof("[proxy] start: method=%s url=%s headers=%d trailers=%d", req.Method, req.URL, len(req.Header), len(req.Trailer))
59-
runHost, err := resolveCloudRunHost(rp.internalDomain, req.Host, rp.currentRegion, rp.projectHash)
59+
klog.V(5).Infof("[director] receive req host=%s", req.Host)
60+
origHost := req.Host
61+
if h, p, err := net.SplitHostPort(origHost); err == nil {
62+
klog.V(6).Infof("discarding port=%v in host=%s", p, origHost)
63+
origHost = h
64+
}
65+
runHost, err := resolveCloudRunHost(rp.internalDomain, origHost, rp.currentRegion, rp.projectHash)
6066
if err != nil {
6167
// this only fails due to region code not being registered –which would be handled
6268
// by the DNS resolver so the request should not come here with an invalid region.
@@ -71,12 +77,11 @@ func (rp *reverseProxy) newReverseProxyHandler(tr http.RoundTripper) http.Handle
7177
*req = *newReq
7278
return
7379
}
74-
origHost := req.Host
7580
req.URL.Scheme = "https"
7681
req.URL.Host = runHost
7782
req.Host = runHost
7883
req.Header.Set("host", runHost)
79-
klog.V(5).Infof("[proxy] rewrote host=%s to=%s newurl=%q", origHost, runHost, req.URL)
84+
klog.V(5).Infof("[director] rewrote host=%s to=%s new_url=%q", origHost, runHost, req.URL)
8085
},
8186
}
8287
}

0 commit comments

Comments
 (0)