Skip to content

Commit

Permalink
Merge pull request kubernetes#37679 from zdj6373/proxy-accept
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue

Code optimization

Accept function, the same sentence information repeated three times, under the optimization, recorded in the call function
  • Loading branch information
Kubernetes Submit Queue authored Dec 5, 2016
2 parents 513893c + e737f32 commit 8117722
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions pkg/kubectl/proxy_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,14 @@ func matchesRegexp(str string, regexps []*regexp.Regexp) bool {

func (f *FilterServer) accept(method, path, host string) bool {
if matchesRegexp(path, f.RejectPaths) {
glog.V(3).Infof("Filter rejecting %v %v %v", method, path, host)
return false
}
if matchesRegexp(method, f.RejectMethods) {
glog.V(3).Infof("Filter rejecting %v %v %v", method, path, host)
return false
}
if matchesRegexp(path, f.AcceptPaths) && matchesRegexp(host, f.AcceptHosts) {
glog.V(3).Infof("Filter accepting %v %v %v", method, path, host)
return true
}
glog.V(3).Infof("Filter rejecting %v %v %v", method, path, host)
return false
}

Expand All @@ -131,9 +127,11 @@ func extractHost(header string) (host string) {
func (f *FilterServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
host := extractHost(req.Host)
if f.accept(req.Method, req.URL.Path, host) {
glog.V(3).Infof("Filter accepting %v %v %v", req.Method, req.URL.Path, host)
f.delegate.ServeHTTP(rw, req)
return
}
glog.V(3).Infof("Filter rejecting %v %v %v", req.Method, req.URL.Path, host)
rw.WriteHeader(http.StatusForbidden)
rw.Write([]byte("<h3>Unauthorized</h3>"))
}
Expand Down

0 comments on commit 8117722

Please sign in to comment.