fix: format IPv6 addr correclty for HTTP URL (#254)

* fix: format IPv6 addr correclty for HTTP URL

* test: cover changes

* test: refactor

---------

Co-authored-by: gm0stache <gm0stache@noreply.codeberg.org>
This commit is contained in:
Gabriel
2026-02-16 21:19:52 +01:00
committed by GitHub
co-authored by gm0stache
parent d3ee7399eb
commit 14056cc584
2 changed files with 38 additions and 2 deletions
+8 -2
View File
@@ -5,7 +5,9 @@ import (
"errors"
"fmt"
"io"
"net"
"net/http"
"net/netip"
"sync"
"time"
@@ -108,8 +110,7 @@ func verifyCaddyReachable(ctx context.Context, m *pb.MachineInfo) error {
eventID := fmt.Sprintf("Machine %s (%s)", m.Name, publicIP)
pw.Event(progress.NewEvent(eventID, progress.Working, "Querying"))
verifyURL := fmt.Sprintf("http://%s%s", publicIP, caddyconfig.VerifyPath)
verifyURL := getVerifyURL(publicIP)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, verifyURL, nil)
if err != nil {
pw.Event(progress.NewEvent(eventID, progress.Error, err.Error()))
@@ -170,6 +171,11 @@ func verifyCaddyReachable(ctx context.Context, m *pb.MachineInfo) error {
}
}
func getVerifyURL(publicIP netip.Addr) string {
httpFormattedIP := net.JoinHostPort(publicIP.String(), "")
return fmt.Sprintf("http://%s%s", httpFormattedIP, caddyconfig.VerifyPath)
}
// unreachable creates a new Unreachable error event.
func unreachable(id string) progress.Event {
return progress.NewEvent(