Rename from_root_domain to from_root_url

This commit is contained in:
bitfl0wer 2023-12-03 13:39:23 +01:00
parent b5ff7e3347
commit 0125c38bd0
3 changed files with 7 additions and 7 deletions

View File

@ -107,12 +107,12 @@ impl Instance {
None
}
/// Creates a new [`Instance`] by trying to get the [relevant instance urls](UrlBundle) from a root domain.
/// Creates a new [`Instance`] by trying to get the [relevant instance urls](UrlBundle) from a root url.
/// Shorthand for `Instance::new(UrlBundle::from_root_domain(root_domain).await?)`.
///
/// If `limited` is `true`, then Chorus will track and enforce rate limits for this instance.
pub async fn from_root_domain(root_domain: &str, limited: bool) -> ChorusResult<Instance> {
let urls = UrlBundle::from_root_domain(root_domain).await?;
pub async fn from_root_url(root_url: &str, limited: bool) -> ChorusResult<Instance> {
let urls = UrlBundle::from_root_url(root_url).await?;
Instance::new(urls, limited).await
}
}

View File

@ -189,7 +189,7 @@ impl UrlBundle {
url_string
}
/// Performs a few HTTP requests to try and retrieve a `UrlBundle` from an instances' root domain.
/// Performs a few HTTP requests to try and retrieve a `UrlBundle` from an instances' root url.
/// The method tries to retrieve the `UrlBundle` via these three strategies, in order:
/// - GET: `$url/.well-known/spacebar` -> Retrieve UrlBundle via `$wellknownurl/api/policies/instance/domains`
/// - GET: `$url/api/policies/instance/domains`
@ -199,7 +199,7 @@ impl UrlBundle {
/// stores the CDN and WSS URLs under the `$api/policies/instance/domains` endpoint. If all three
/// of the above approaches fail, it is very likely that the instance is misconfigured, unreachable, or that
/// a wrong URL was provided.
pub async fn from_root_domain(url: &str) -> ChorusResult<UrlBundle> {
pub async fn from_root_url(url: &str) -> ChorusResult<UrlBundle> {
let parsed = UrlBundle::parse_url(url.to_string());
let client = reqwest::Client::new();
let request_wellknown = client

View File

@ -11,9 +11,9 @@ wasm_bindgen_test_configure!(run_in_browser);
async fn test_parse_url() {
// TODO: Currently only tests two of the three branches in UrlBundle::from_root_domain.
let url = url::Url::parse("http://localhost:3001/").unwrap();
UrlBundle::from_root_domain(url.as_str()).await.unwrap();
UrlBundle::from_root_url(url.as_str()).await.unwrap();
let url = url::Url::parse("http://localhost:3001/api/").unwrap();
UrlBundle::from_root_domain(url.as_str()).await.unwrap();
UrlBundle::from_root_url(url.as_str()).await.unwrap();
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]