Support url without protocol in nip11.Fetch

This commit is contained in:
Daniele Tonon 2024-03-09 19:48:25 +01:00 committed by fiatjaf_
parent aea2895441
commit ec1e86e505

View File

@ -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)