fix(module,app): use whole remote address if splitting fail
All checks were successful
arcad/edge/pipeline/head This commit looks good

This commit is contained in:
wpetit 2023-04-21 20:01:43 +02:00
parent f99b1ac6ac
commit abc60b9ae3

View File

@ -73,12 +73,7 @@ func (h *Handler) serveAppURL(w http.ResponseWriter, r *http.Request) {
from := req.From
if from == "" {
host, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
logger.Warn(ctx, "could not split remote address", logger.E(errors.WithStack(err)))
} else {
from = host
}
from = retrieveRemoteAddr(r)
}
url, err := h.repo.GetURL(ctx, appID, from)
@ -110,3 +105,12 @@ func Mount(repository Repository) MountFunc {
r.Post("/api/v1/apps/{appID}/url", handler.serveAppURL)
}
}
func retrieveRemoteAddr(r *http.Request) string {
host, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
host = r.RemoteAddr
}
return host
}