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

This commit is contained in:
wpetit 2023-04-21 20:01:43 +02:00
parent f99b1ac6ac
commit abc60b9ae3
1 changed files with 10 additions and 6 deletions

View File

@ -73,12 +73,7 @@ func (h *Handler) serveAppURL(w http.ResponseWriter, r *http.Request) {
from := req.From from := req.From
if from == "" { if from == "" {
host, _, err := net.SplitHostPort(r.RemoteAddr) from = retrieveRemoteAddr(r)
if err != nil {
logger.Warn(ctx, "could not split remote address", logger.E(errors.WithStack(err)))
} else {
from = host
}
} }
url, err := h.repo.GetURL(ctx, appID, from) 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) 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
}