diff --git a/staging/src/k8s.io/kubectl/pkg/proxy/proxy_server.go b/staging/src/k8s.io/kubectl/pkg/proxy/proxy_server.go index db797fa0c54..2b21bb4c9dd 100644 --- a/staging/src/k8s.io/kubectl/pkg/proxy/proxy_server.go +++ b/staging/src/k8s.io/kubectl/pkg/proxy/proxy_server.go @@ -174,6 +174,22 @@ func makeUpgradeTransport(config *rest.Config, keepalive time.Duration) (proxy.U // NewServer creates and installs a new Server. // 'filter', if non-nil, protects requests to the api only. func NewServer(filebase string, apiProxyPrefix string, staticPrefix string, filter *FilterServer, cfg *rest.Config, keepalive time.Duration) (*Server, error) { + proxyHandler, err := NewProxyHandler(apiProxyPrefix, filter, cfg, keepalive) + if err != nil { + return nil, err + } + mux := http.NewServeMux() + mux.Handle(apiProxyPrefix, proxyHandler) + if filebase != "" { + // Require user to explicitly request this behavior rather than + // serving their working directory by default. + mux.Handle(staticPrefix, newFileHandler(staticPrefix, filebase)) + } + return &Server{handler: mux}, nil +} + +// NewProxyHandler creates an api proxy handler for the cluster +func NewProxyHandler(apiProxyPrefix string, filter *FilterServer, cfg *rest.Config, keepalive time.Duration) (http.Handler, error) { host := cfg.Host if !strings.HasSuffix(host, "/") { host = host + "/" @@ -204,15 +220,7 @@ func NewServer(filebase string, apiProxyPrefix string, staticPrefix string, filt if !strings.HasPrefix(apiProxyPrefix, "/api") { proxyServer = stripLeaveSlash(apiProxyPrefix, proxyServer) } - - mux := http.NewServeMux() - mux.Handle(apiProxyPrefix, proxyServer) - if filebase != "" { - // Require user to explicitly request this behavior rather than - // serving their working directory by default. - mux.Handle(staticPrefix, newFileHandler(staticPrefix, filebase)) - } - return &Server{handler: mux}, nil + return proxyServer, nil } // Listen is a simple wrapper around net.Listen.