@@ -12,6 +12,7 @@ use alloc::vec::Vec;
12
12
use core:: fmt;
13
13
use std:: net:: SocketAddr ;
14
14
15
+ use reqwest:: Client ;
15
16
#[ cfg( not( target_arch = "wasm32" ) ) ]
16
17
use reqwest:: Proxy ;
17
18
@@ -188,9 +189,7 @@ impl RelayInformationDocument {
188
189
/// Get Relay Information Document
189
190
///
190
191
/// **Proxy is ignored for WASM targets!**
191
- pub async fn get ( url : Url , _proxy : Option < SocketAddr > ) -> Result < Self , Error > {
192
- use reqwest:: Client ;
193
-
192
+ pub async fn get ( mut url : Url , _proxy : Option < SocketAddr > ) -> Result < Self , Error > {
194
193
#[ cfg( not( target_arch = "wasm32" ) ) ]
195
194
let client: Client = {
196
195
let mut builder = Client :: builder ( ) ;
@@ -204,10 +203,8 @@ impl RelayInformationDocument {
204
203
#[ cfg( target_arch = "wasm32" ) ]
205
204
let client: Client = Client :: new ( ) ;
206
205
207
- let url = Self :: with_http_scheme ( url) ?;
208
- let req = client
209
- . get ( url. to_string ( ) )
210
- . header ( "Accept" , "application/nostr+json" ) ;
206
+ let url: & str = Self :: with_http_scheme ( & mut url) ?;
207
+ let req = client. get ( url) . header ( "Accept" , "application/nostr+json" ) ;
211
208
match req. send ( ) . await {
212
209
Ok ( response) => {
213
210
let json: String = response. text ( ) . await ?;
@@ -222,14 +219,13 @@ impl RelayInformationDocument {
222
219
223
220
/// Returns new URL with scheme substituted to HTTP(S) if WS(S) was provided,
224
221
/// other schemes leaves untouched.
225
- fn with_http_scheme ( url : Url ) -> Result < Url , Error > {
226
- let mut url = url;
222
+ fn with_http_scheme ( url : & mut Url ) -> Result < & str , Error > {
227
223
match url. scheme ( ) {
228
224
"wss" => url. set_scheme ( "https" ) . map_err ( |_| Error :: InvalidScheme ) ?,
229
225
"ws" => url. set_scheme ( "http" ) . map_err ( |_| Error :: InvalidScheme ) ?,
230
226
_ => { }
231
227
}
232
- Ok ( url)
228
+ Ok ( url. as_str ( ) )
233
229
}
234
230
}
235
231
0 commit comments