Skip to main content

tuwunel_admin/federation/
fetch_support_well_known.rs

1use ruma::OwnedServerName;
2use tuwunel_core::{Err, Result};
3use tuwunel_service::client::read_response_capped;
4
5use crate::admin_command;
6
7#[admin_command]
8pub(super) async fn fetch_support_well_known(&self, server_name: OwnedServerName) -> Result {
9	let response = self
10		.services
11		.client
12		.default
13		.get(format!("https://{server_name}/.well-known/matrix/support"))
14		.send()
15		.await?;
16
17	let body = read_response_capped(response, 1500).await?;
18
19	if body.is_empty() {
20		return Err!("Response text/body is empty.");
21	}
22
23	let json: serde_json::Value = match serde_json::from_slice(&body) {
24		| Ok(json) => json,
25		| Err(_) => {
26			return Err!("Response text/body is not valid JSON.",);
27		},
28	};
29
30	let pretty_json: String = match serde_json::to_string_pretty(&json) {
31		| Ok(json) => json,
32		| Err(_) => {
33			return Err!("Response text/body is not valid JSON.",);
34		},
35	};
36
37	write!(self, "Got JSON response:\n\n```json\n{pretty_json}\n```").await
38}