kubectl: Handle splitting host:port when no port is present

In the proxy filter, if listening on port 80 or 443 there will
be no port present in the Host: HTTP header. Just use the entire
thing in these cases, and don't reject requests when no port
is present in the Host: HTTP header.
This commit is contained in:
Stef Walter
2015-07-02 14:46:43 +02:00
parent 9d32830040
commit 3db0bfdf65
2 changed files with 23 additions and 1 deletions

View File

@@ -106,8 +106,17 @@ func (f *FilterServer) HandlerFor(delegate http.Handler) *FilterServer {
return &f2
}
// Get host from a host header value like "localhost" or "localhost:8080"
func extractHost(header string) (host string) {
host, _, err := net.SplitHostPort(header)
if err != nil {
host = header
}
return host
}
func (f *FilterServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
host, _, _ := net.SplitHostPort(req.Host)
host := extractHost(req.Host)
if f.accept(req.Method, req.URL.Path, host) {
f.delegate.ServeHTTP(rw, req)
return