remove comments and add the container name
This commit is contained in:
parent
6a1c6c5967
commit
52b4d44b4b
@ -151,7 +151,7 @@ func (ph *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.Debug().Str("remote_addr", r.RemoteAddr).Str("method", r.Method).Str("path", r.URL.Path).Msg("incoming request")
|
log.Debug().Str("remote_addr", r.RemoteAddr).Str("method", r.Method).Str("path", r.URL.Path).Msg("incoming request")
|
||||||
mr, ok := containerMethodRegex["*"]
|
mr, ok := containerMethodRegex["*"]
|
||||||
if ok {
|
if ok {
|
||||||
if ph.checkMethodAndRegex(r, mr) {
|
if ph.checkMethodAndRegex(mr, r, "") {
|
||||||
ph.rp.ServeHTTP(w, r)
|
ph.rp.ServeHTTP(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -168,7 +168,7 @@ func (ph *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
for _, resolvedIP := range resolvedIPs {
|
for _, resolvedIP := range resolvedIPs {
|
||||||
if resolvedIP.Equal(net.ParseIP(host)) {
|
if resolvedIP.Equal(net.ParseIP(host)) {
|
||||||
if ph.checkMethodAndRegex(r, mr) {
|
if ph.checkMethodAndRegex(mr, r, containerName) {
|
||||||
authorized = true
|
authorized = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -203,23 +203,18 @@ func logAuthorizedRequest(r *http.Request, containerName, message string) {
|
|||||||
l.Msg(message)
|
l.Msg(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ph *ProxyHandler) checkMethodAndRegex(r *http.Request, mr methodRegex) bool {
|
func (ph *ProxyHandler) checkMethodAndRegex(mr methodRegex, r *http.Request, containerName string) bool {
|
||||||
req, ok := mr[r.Method]
|
req, ok := mr[r.Method]
|
||||||
if !ok {
|
if !ok {
|
||||||
logDeniedRequest(r, http.StatusMethodNotAllowed, "this HTTP method is not in the list of those authorized for this container")
|
logDeniedRequest(r, http.StatusMethodNotAllowed, "this HTTP method is not in the list of those authorized for this container")
|
||||||
return false
|
return false
|
||||||
// http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
|
|
||||||
// return
|
|
||||||
}
|
}
|
||||||
if !req.MatchString(r.URL.Path) {
|
if !req.MatchString(r.URL.Path) {
|
||||||
logDeniedRequest(r, http.StatusForbidden, "this path does not match any regular expression for this HTTP method")
|
logDeniedRequest(r, http.StatusForbidden, "this path does not match any regular expression for this HTTP method")
|
||||||
return false
|
return false
|
||||||
// http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
|
|
||||||
// return
|
|
||||||
}
|
}
|
||||||
logAuthorizedRequest(r, "", "incoming request matches a registered regular expression")
|
logAuthorizedRequest(r, containerName, "incoming request matches a registered regular expression")
|
||||||
return true
|
return true
|
||||||
// ph.rp.ServeHTTP(w, r)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// action is executed when the ServeCmd command is called.
|
// action is executed when the ServeCmd command is called.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user