diff --git a/pubky/src/lib.rs b/pubky/src/lib.rs index e8dedf6..4392ff2 100644 --- a/pubky/src/lib.rs +++ b/pubky/src/lib.rs @@ -26,6 +26,7 @@ pub struct Client { #[cfg(not(target_arch = "wasm32"))] pub(crate) cookie_store: Arc, http: reqwest::Client, + icann_http: reqwest::Client, pub(crate) pkarr: pkarr::Client, } diff --git a/pubky/src/native.rs b/pubky/src/native.rs index 63fa8c2..0c971d6 100644 --- a/pubky/src/native.rs +++ b/pubky/src/native.rs @@ -52,17 +52,26 @@ impl Settings { let cookie_store = Arc::new(CookieJar::default()); + // TODO: allow custom user agent, but force a Pubky user agent information + let user_agent = DEFAULT_USER_AGENT; + let http = reqwest::ClientBuilder::from(pkarr.clone()) // TODO: use persistent cookie jar .cookie_provider(cookie_store.clone()) - // TODO: allow custom user agent, but force a Pubky user agent information - .user_agent(DEFAULT_USER_AGENT) + .user_agent(user_agent) + .build() + .expect("config expected to not error"); + + let icann_http = reqwest::ClientBuilder::new() + .cookie_provider(cookie_store.clone()) + .user_agent(user_agent) .build() .expect("config expected to not error"); Ok(Client { cookie_store, http, + icann_http, pkarr, }) } diff --git a/pubky/src/native/http.rs b/pubky/src/native/http.rs index e04883f..168e43e 100644 --- a/pubky/src/native/http.rs +++ b/pubky/src/native/http.rs @@ -1,5 +1,6 @@ //! HTTP methods that support `https://` with Pkarr domains, and `pubky://` URLs +use pkarr::PublicKey; use reqwest::{IntoUrl, Method, RequestBuilder}; use crate::Client; @@ -27,6 +28,8 @@ impl Client { let url = format!("https://_pubky.{}", url.split_at(8).1); return self.http.request(method, url); + } else if url.starts_with("https://") && PublicKey::try_from(url).is_err() { + return self.icann_http.request(method, url); } self.http.request(method, url) @@ -152,10 +155,8 @@ mod tests { let client = Client::test(&testnet); - let url = format!("http://example.com/"); - let response = client - .request(Default::default(), url) + .request(Default::default(), "https://example.com/") .send() .await .unwrap();