From 47538621c9edc4318458df16a66c84f9a6065acc Mon Sep 17 00:00:00 2001 From: Adrien PONSIN Date: Thu, 17 Apr 2025 14:17:04 +0200 Subject: [PATCH] call ServeHTTP --- command/serve.go | 51 +----------------------------------------------- 1 file changed, 1 insertion(+), 50 deletions(-) diff --git a/command/serve.go b/command/serve.go index d5db8ce..3cb5e51 100644 --- a/command/serve.go +++ b/command/serve.go @@ -179,14 +179,8 @@ func (ph *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { Str("path", r.URL.Path). Str("decision", "authorized"). Msg("incoming request matches a registered regular expression") + ph.rp.ServeHTTP(w, r) return - /* - if err := checkMethodPath(r, mr); err != nil { - handleError(w, err) - log.Err(err).Send() - return - } - */ } var ( containerName string @@ -195,7 +189,6 @@ func (ph *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { for containerName, mr = range containerMethodRegex { resolvedIPs, err := net.LookupIP(containerName) if err != nil { - // log.Warn().Err(err).Msg("this error may be transient due to the unavailability of one of the services") continue } for _, resolvedIP := range resolvedIPs { @@ -222,13 +215,6 @@ func (ph *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden) return } - /* - if err = checkMethodPath(r, mr); err != nil { - handleError(w, err) - log.Err(err).Send() - return - } - */ log.Info(). Str("remote_addr", r.RemoteAddr). Str("method", r.Method). @@ -249,29 +235,6 @@ func (ph *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { Msg("this container is not on the list of authorized ones") http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) return - /* - log.Warn(). - Str("remote_addr", r.RemoteAddr). - Str("method", r.Method). - Str("path", r.URL.Path). - Str("decision", "denied"). - Msg("this error may be transient due to the unavailability of one of the services") - http.Error(w, http.StatusText(http.StatusServiceUnavailable), http.StatusServiceUnavailable) - return - */ -} - -// checkMethodPath executes the regular expression on the path of the HTTP request if and only if -// the latter's HTTP method is actually present in the list of authorized HTTP methods. -func checkMethodPath(r *http.Request, mr methodRegex) error { - req, ok := mr[r.Method] - if !ok { - return ErrHTTPMethodNotAllowed{httpMethod: r.Method} - } - if !req.MatchString(r.URL.Path) { - return ErrNoMatch{path: r.URL.Path, httpMethod: r.Method} - } - return nil } // action is executed when the ServeCmd command is called. @@ -540,15 +503,3 @@ func registerMethodRegex(containerName, urlRegex string, httpMethods []string) e } return nil } - -func handleError(w http.ResponseWriter, err error) { - var methodNotAllowedErr ErrHTTPMethodNotAllowed - var noMatchErr ErrNoMatch - if errors.As(err, &methodNotAllowedErr) { - http.Error(w, err.Error(), http.StatusMethodNotAllowed) - } else if errors.As(err, &noMatchErr) { - http.Error(w, err.Error(), http.StatusForbidden) - } else { - http.Error(w, err.Error(), http.StatusInternalServerError) - } -}