From ec1e86e505b06220e416e99dafc486ab5a8bc8ba Mon Sep 17 00:00:00 2001 From: Daniele Tonon Date: Sat, 9 Mar 2024 19:48:25 +0100 Subject: [PATCH] Support url without protocol in nip11.Fetch --- nip11/fetch.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nip11/fetch.go b/nip11/fetch.go index 1bfc1e7..3c201f1 100644 --- a/nip11/fetch.go +++ b/nip11/fetch.go @@ -18,10 +18,13 @@ func Fetch(ctx context.Context, u string) (info *RelayInformationDocument, err e defer cancel() } - // normalize URL to start with http:// or https:// - if strings.HasPrefix(u, "ws") { + // 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, "/") req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)