remove unnecessary appservice reqwest timeout, reduce couple unwraps, return if unsuccessful HTTP response

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-04-24 00:43:31 -04:00 committed by June
parent 46ce15f61f
commit eb5dcf08c6
2 changed files with 6 additions and 10 deletions

View file

@ -60,9 +60,6 @@ impl Service {
let reqwest_request = reqwest::Request::try_from(http_request)?; let reqwest_request = reqwest::Request::try_from(http_request)?;
// TODO: we could keep this very short and let expo backoff do it's thing...
//*reqwest_request.timeout_mut() = Some(Duration::from_secs(5));
if let Some(url_host) = reqwest_request.url().host_str() { if let Some(url_host) = reqwest_request.url().host_str() {
trace!("Checking request URL for IP"); trace!("Checking request URL for IP");
if let Ok(ip) = IPAddress::parse(url_host) { if let Ok(ip) = IPAddress::parse(url_host) {

View file

@ -1,4 +1,4 @@
use std::{fmt::Debug, mem, time::Duration}; use std::{fmt::Debug, mem};
use bytes::BytesMut; use bytes::BytesMut;
use ruma::api::{appservice::Registration, IncomingResponse, MatrixVersion, OutgoingRequest, SendAccessToken}; use ruma::api::{appservice::Registration, IncomingResponse, MatrixVersion, OutgoingRequest, SendAccessToken};
@ -25,8 +25,7 @@ where
.map_err(|e| { .map_err(|e| {
warn!("Failed to find destination {}: {}", destination, e); warn!("Failed to find destination {}: {}", destination, e);
Error::BadServerResponse("Invalid destination") Error::BadServerResponse("Invalid destination")
}) })?
.unwrap()
.map(BytesMut::freeze); .map(BytesMut::freeze);
let mut parts = http_request.uri().clone().into_parts(); let mut parts = http_request.uri().clone().into_parts();
@ -44,9 +43,7 @@ where
); );
*http_request.uri_mut() = parts.try_into().expect("our manipulation is always valid"); *http_request.uri_mut() = parts.try_into().expect("our manipulation is always valid");
let mut reqwest_request = reqwest::Request::try_from(http_request)?; let reqwest_request = reqwest::Request::try_from(http_request)?;
*reqwest_request.timeout_mut() = Some(Duration::from_secs(120));
let url = reqwest_request.url().clone(); let url = reqwest_request.url().clone();
@ -89,6 +86,8 @@ where
url, url,
utils::string_from_bytes(&body) utils::string_from_bytes(&body)
); );
return Err(Error::BadServerResponse("Appservice returned unsuccessful HTTP response"));
} }
let response = T::IncomingResponse::try_from_http_response( let response = T::IncomingResponse::try_from_http_response(
@ -99,6 +98,6 @@ where
response.map(Some).map_err(|_| { response.map(Some).map_err(|_| {
warn!("Appservice returned invalid response bytes {}\n{}", destination, url); warn!("Appservice returned invalid response bytes {}\n{}", destination, url);
Error::BadServerResponse("Server returned bad response.") Error::BadServerResponse("Appservice returned bad/invalid response")
}) })
} }