From 3a0b43611e1bee673fa14ef0030b5a952a246898 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Tue, 18 Aug 2026 13:32:26 +0900 Subject: [PATCH] fetch, group: only treat exact localhost hosts as http, and apply the same scheme guessing to group web addresses so local relays work. --- fetch.go | 11 ++++++++++- group.go | 7 ++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/fetch.go b/fetch.go index 1344028..910848c 100644 --- a/fetch.go +++ b/fetch.go @@ -176,7 +176,16 @@ func isWebAddress(code string) bool { func guessWebScheme(code string) string { host, _, _ := strings.Cut(code, "/") - if strings.HasPrefix(host, "localhost") || strings.HasPrefix(host, "127.0.0.1") { + if strings.HasPrefix(host, "[") { + // ipv6 literal, keep only the bracketed part + if i := strings.Index(host, "]"); i != -1 { + host = host[:i+1] + } + } else if h, _, ok := strings.Cut(host, ":"); ok { + // strip port + host = h + } + if host == "localhost" || host == "127.0.0.1" || host == "[::1]" { return "http://" } return "https://" diff --git a/group.go b/group.go index 92f1564..68a5fe7 100644 --- a/group.go +++ b/group.go @@ -995,7 +995,12 @@ func parseGroupIdentifier(ctx context.Context, c *cli.Command) (relay string, id identifier = ptr.Identifier author = ptr.PublicKey } else if isWebAddress(groupArg) { - webPath, err := nipad.Resolve(ctx, groupArg) + addr := groupArg + if !strings.HasPrefix(addr, "http://") && !strings.HasPrefix(addr, "https://") { + addr = guessWebScheme(addr) + addr + } + + webPath, err := nipad.Resolve(ctx, addr) if err != nil { return "", "", nostr.ZeroPK, fmt.Errorf("failed to resolve group address '%s': %w", groupArg, err) }