mirror of
https://github.com/fiatjaf/nak.git
synced 2026-10-05 15:18:23 +00:00
Merge pull request #202 from mattn/fix/web-scheme-guessing
fetch, group: fix web address scheme guessing
This commit is contained in:
@@ -176,7 +176,16 @@ func isWebAddress(code string) bool {
|
|||||||
|
|
||||||
func guessWebScheme(code string) string {
|
func guessWebScheme(code string) string {
|
||||||
host, _, _ := strings.Cut(code, "/")
|
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 "http://"
|
||||||
}
|
}
|
||||||
return "https://"
|
return "https://"
|
||||||
|
|||||||
@@ -1029,7 +1029,12 @@ func parseGroupIdentifier(ctx context.Context, c *cli.Command) (relay string, id
|
|||||||
identifier = ptr.Identifier
|
identifier = ptr.Identifier
|
||||||
author = ptr.PublicKey
|
author = ptr.PublicKey
|
||||||
} else if isWebAddress(groupArg) {
|
} 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 {
|
if err != nil {
|
||||||
return "", "", nostr.ZeroPK, fmt.Errorf("failed to resolve group address '%s': %w", groupArg, err)
|
return "", "", nostr.ZeroPK, fmt.Errorf("failed to resolve group address '%s': %w", groupArg, err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user