diff --git a/nip11/fetch.go b/nip11/fetch.go index 3c201f1..4627f05 100644 --- a/nip11/fetch.go +++ b/nip11/fetch.go @@ -5,8 +5,9 @@ import ( "encoding/json" "fmt" "net/http" - "strings" "time" + + "github.com/nbd-wtf/go-nostr" ) // Fetch fetches the NIP-11 RelayInformationDocument. @@ -19,14 +20,9 @@ func Fetch(ctx context.Context, u string) (info *RelayInformationDocument, err e } // normalize URL to start with http://, https:// or without protocol - if strings.HasPrefix(u, "wss://") || strings.HasPrefix(u, "ws://") { - u = "http" + u[2:] - } - if !(strings.HasPrefix(u, "http://") || strings.HasPrefix(u, "https://")) { - u = "http://" + u - } - u = strings.TrimRight(u, "/") + u = "http" + nostr.NormalizeURL(u)[2:] + // make request req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil) // add the NIP-11 header diff --git a/nip11/nip11_test.go b/nip11/nip11_test.go index b3abdc2..9e4e6dd 100644 --- a/nip11/nip11_test.go +++ b/nip11/nip11_test.go @@ -41,4 +41,8 @@ func TestFetch(t *testing.T) { if err != nil || res.Name == "" { t.Errorf("failed to fetch from https") } + res, err = Fetch(context.Background(), "relay.nostr.bg") + if err != nil || res.Name == "" { + t.Errorf("failed to fetch without protocol") + } }