Add NewProxyHandler func
Kubernetes-commit: 930cfe74087080440b1abc58d7918e2fd435377d
This commit is contained in:
parent
5ab226ab1d
commit
8226a30e69
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue