From b9ee89892069deeef865f77b0e62326f2270c11e Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Thu, 12 Sep 2024 17:12:49 -0700 Subject: [PATCH] require client base_url, rename from authority The previous code used `server_name` as a fallback but in reality there is no real relationship between `server_name` and the location clients are supposed to make requests to. Additionally, the `insecure` option is gone, because we now allow users to control the entire URL, so they're free to choose the scheme. --- book/changelog.md | 7 +++++-- src/api/well_known.rs | 20 +++----------------- src/config.rs | 15 +++++---------- 3 files changed, 13 insertions(+), 29 deletions(-) diff --git a/book/changelog.md b/book/changelog.md index b397fa27..ddd97572 100644 --- a/book/changelog.md +++ b/book/changelog.md @@ -225,8 +225,11 @@ This will be the first release of Grapevine since it was forked from Conduit [!84](https://gitlab.computer.surgery/matrix/grapevine-fork/-/merge_requests/84)) 15. Added support for Authenticated Media ([MSC3916](https://github.com/matrix-org/matrix-spec-proposals/pull/3916)). ([!58](https://gitlab.computer.surgery/matrix/grapevine-fork/-/merge_requests/58)) -16. Added support for configuring and serving `/.well-known/matrix/...` data. - ([!90](https://gitlab.computer.surgery/matrix/grapevine-fork/-/merge_requests/90)) +16. **BREAKING:** Added support for configuring and serving + `/.well-known/matrix/...` data. + ([!90](https://gitlab.computer.surgery/matrix/grapevine-fork/-/merge_requests/90), + [!94](https://gitlab.computer.surgery/matrix/grapevine-fork/-/merge_requests/94)) + * The `server_discovery.client.base_url` option is now required. 17. Added support for configuring old verify/signing keys in config (`federation.old_verify_keys`) ([!96](https://gitlab.computer.surgery/matrix/grapevine-fork/-/merge_requests/96)) 18. Added admin commands to delete media diff --git a/src/api/well_known.rs b/src/api/well_known.rs index f0c0df07..44210e55 100644 --- a/src/api/well_known.rs +++ b/src/api/well_known.rs @@ -30,24 +30,10 @@ pub(crate) async fn server( /// Handler for `/.well-known/matrix/client` pub(crate) async fn client(_: Ar) -> Ra { - let authority = services() - .globals - .config - .server_discovery - .client - .authority - .clone() - .unwrap_or_else(|| services().globals.config.server_name.clone()); - - let scheme = if services().globals.config.server_discovery.client.insecure { - "http" - } else { - "https" - }; - - let base_url = format!("{scheme}://{authority}"); - // I wish ruma used an actual URL type instead of `String` + let base_url = + services().globals.config.server_discovery.client.base_url.to_string(); + Ra(client::Response { homeserver: client::HomeserverInfo::new(base_url.clone()), identity_server: None, diff --git a/src/config.rs b/src/config.rs index 01e65bc1..e2c2b0ff 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,6 +7,7 @@ use std::{ }; use once_cell::sync::Lazy; +use reqwest::Url; use ruma::{ api::federation::discovery::OldVerifyKey, OwnedServerName, OwnedServerSigningKeyId, RoomVersionId, @@ -39,7 +40,6 @@ pub(crate) struct Config { /// This is the value that will appear e.g. in user IDs and room aliases. pub(crate) server_name: OwnedServerName, - #[serde(default)] pub(crate) server_discovery: ServerDiscovery, pub(crate) database: DatabaseConfig, #[serde(default)] @@ -73,14 +73,13 @@ pub(crate) struct Config { pub(crate) emergency_password: Option, } -#[derive(Debug, Default, Deserialize)] +#[derive(Debug, Deserialize)] pub(crate) struct ServerDiscovery { /// Server-server discovery configuration #[serde(default)] pub(crate) server: ServerServerDiscovery, /// Client-server discovery configuration - #[serde(default)] pub(crate) client: ClientServerDiscovery, } @@ -92,14 +91,10 @@ pub(crate) struct ServerServerDiscovery { } /// Client-server discovery configuration -#[derive(Debug, Default, Deserialize)] +#[derive(Debug, Deserialize)] pub(crate) struct ClientServerDiscovery { - /// The alternative authority to make client-server API requests to - pub(crate) authority: Option, - - /// Controls whether HTTPS is used - #[serde(default)] - pub(crate) insecure: bool, + /// The base URL to make client-server API requests to + pub(crate) base_url: Url, #[serde(default, rename = "advertise_buggy_sliding_sync")] pub(crate) advertise_sliding_sync: bool,