Skip to content

Commit

Permalink
Support url without protocol in nip11.Fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
dtonon authored and fiatjaf committed Mar 9, 2024
1 parent aea2895 commit ec1e86e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions nip11/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ec1e86e

Please sign in to comment.