bug fixed?

This commit is contained in:
Adrien PONSIN 2025-04-15 20:39:44 +02:00
parent f84ad18dfd
commit 7011d71c03
No known key found for this signature in database
GPG Key ID: 7B4D4A32C05C475E

View File

@ -151,9 +151,7 @@ func (ph *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log.Debug().Str("remote_addr", r.RemoteAddr).Str("http_method", r.Method).Str("path", r.URL.Path).Msg("incoming request")
mr, ok := containerMethodRegex["*"]
if ok {
fmt.Println("here 1")
if err := checkMethodPath(w, r, mr); err != nil {
fmt.Println("failed here 1")
log.Err(err).Send()
return
}
@ -167,41 +165,31 @@ func (ph *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
resolvedIPs, err := net.LookupIP(containerName)
if err != nil {
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
fmt.Println("failed here 2")
log.Err(err).Send()
return
}
fmt.Printf("count of resolved IPs: %d\n", len(resolvedIPs))
for _, resolvedIP := range resolvedIPs {
fmt.Printf("resolvedIP: %s -- IP: %s", resolvedIP.String(), ip.String())
if resolvedIP.Equal(ip) {
// fmt.Printf("%s == %s\n", resolvedIP.String(), ip.String())
if err = checkMethodPath(w, r, mr); err != nil {
fmt.Println("failed here 3")
log.Err(err).Send()
return
}
fmt.Println("here 2")
}
fmt.Println("here 3")
}
fmt.Println("here 4")
}
fmt.Println("here 5")
}
ph.rp.ServeHTTP(w, r)
}
}
}
}
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(w http.ResponseWriter, r *http.Request, mr methodRegex) error {
req, ok := mr[r.Method]
if !ok {
fmt.Printf("%s is not a registered HTTP method\n", r.Method)
http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
return ErrHTTPMethodNotAllowed{httpMethod: r.Method}
}
log.Debug().Msgf("%s is a registered HTTP method", r.Method)
if !req.MatchString(r.URL.Path) {
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
return ErrNoMatch{
@ -209,7 +197,6 @@ func checkMethodPath(w http.ResponseWriter, r *http.Request, mr methodRegex) err
httpMethod: r.Method,
}
}
log.Debug().Msgf("%s matches %s", r.URL.Path, req.String())
return nil
}