Merge pull request #97675 from wanghaoran1988/proxy_handler
Add NewProxyHandler func Kubernetes-commit: f2e1ee050080cae6b07c8dafaff2dd6f9cc5871d
This commit is contained in:
commit
a3ae203ba2
|
|
@ -924,7 +924,7 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api",
|
||||
"Rev": "47952fe781b3"
|
||||
"Rev": "4e9f5db10201"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery",
|
||||
|
|
|
|||
4
go.mod
4
go.mod
|
|
@ -34,7 +34,7 @@ require (
|
|||
github.com/stretchr/testify v1.6.1
|
||||
golang.org/x/sys v0.0.0-20201112073958-5cba982894dd
|
||||
gopkg.in/yaml.v2 v2.2.8
|
||||
k8s.io/api v0.0.0-20210106170055-47952fe781b3
|
||||
k8s.io/api v0.0.0-20210107085826-4e9f5db10201
|
||||
k8s.io/apimachinery v0.0.0-20210106165743-6c16abd71758
|
||||
k8s.io/cli-runtime v0.0.0-20201218091240-9547a43879a0
|
||||
k8s.io/client-go v0.0.0-20210106050432-9761a13537eb
|
||||
|
|
@ -49,7 +49,7 @@ require (
|
|||
)
|
||||
|
||||
replace (
|
||||
k8s.io/api => k8s.io/api v0.0.0-20210106170055-47952fe781b3
|
||||
k8s.io/api => k8s.io/api v0.0.0-20210107085826-4e9f5db10201
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20210106165743-6c16abd71758
|
||||
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20201218091240-9547a43879a0
|
||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20210106050432-9761a13537eb
|
||||
|
|
|
|||
2
go.sum
2
go.sum
|
|
@ -632,7 +632,7 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh
|
|||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
k8s.io/api v0.0.0-20210106170055-47952fe781b3/go.mod h1:jMmEuFXZmOAJP842CJAbtlCqWhG/8ZuH9/e/xQT+Xq8=
|
||||
k8s.io/api v0.0.0-20210107085826-4e9f5db10201/go.mod h1:3Xl3BjPKHhLlv0+0TYKMZ8NNiKsby57AFDZIBy5Rv0o=
|
||||
k8s.io/apimachinery v0.0.0-20210106165743-6c16abd71758/go.mod h1:WlLqWAHZGg07AeltaI0MV5uk1Omp8xaN0JGLY6gkRpU=
|
||||
k8s.io/cli-runtime v0.0.0-20201218091240-9547a43879a0/go.mod h1:YGZiEr0qwB6XSdVC2kbXtQG/+bm7+18eWKXckr167Io=
|
||||
k8s.io/client-go v0.0.0-20210106050432-9761a13537eb/go.mod h1:MzH4jwc+euEAiFUHId2xQ1P0F4jHAQrNxngF8rnIIqY=
|
||||
|
|
|
|||
|
|
@ -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