Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NewProxyHandler func #97675

Merged
merged 1 commit into from Jan 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 17 additions & 9 deletions staging/src/k8s.io/kubectl/pkg/proxy/proxy_server.go
Expand Up @@ -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 + "/"
Expand Down Expand Up @@ -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.
Expand Down