From 08a183e8c724455ff113b26b32bade1ffb38f8f3 Mon Sep 17 00:00:00 2001 From: strawberry Date: Wed, 24 Jan 2024 21:07:53 -0500 Subject: [PATCH] assume well-known is None if text length exceeds 10000 chars Signed-off-by: strawberry --- src/api/server_server.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/api/server_server.rs b/src/api/server_server.rs index 58db059f..54c02764 100644 --- a/src/api/server_server.rs +++ b/src/api/server_server.rs @@ -595,14 +595,25 @@ async fn request_well_known(destination: &str) -> Option { .await; debug!("Got well known response"); debug!("Well known response: {:?}", response); + if let Err(e) = &response { debug!("Well known error: {e:?}"); return None; } + let text = response.ok()?.text().await; + debug!("Got well known response text"); debug!("Well known response text: {:?}", text); + + if text.as_ref().ok()?.len() > 10000 { + info!("Well known response for destination '{destination}' exceeded past 10000 characters, assuming no well-known."); + return None; + } + let body: serde_json::Value = serde_json::from_str(&text.ok()?).ok()?; + debug!("serde_json body of well known text: {}", body); + Some(body.get("m.server")?.as_str()?.to_owned()) }