Skip to content
Snippets Groups Projects
Commit eb5dcf08 authored by 🥺's avatar 🥺 :transgender_flag: Committed by 🥺
Browse files

remove unnecessary appservice reqwest timeout, reduce couple unwraps, return...

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

Signed-off-by: default avatarstrawberry <strawberry@puppygock.gay>
parent 46ce15f6
No related branches found
No related tags found
No related merge requests found
...@@ -60,9 +60,6 @@ pub(crate) async fn send_request<T>(&self, dest: &str, request: T) -> Result<T:: ...@@ -60,9 +60,6 @@ pub(crate) async fn send_request<T>(&self, dest: &str, request: T) -> Result<T::
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) {
......
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 @@ pub(crate) async fn send_request<T>(registration: Registration, request: T) -> R ...@@ -25,8 +25,7 @@ pub(crate) async fn send_request<T>(registration: Registration, request: T) -> R
.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 @@ pub(crate) async fn send_request<T>(registration: Registration, request: T) -> R ...@@ -44,9 +43,7 @@ pub(crate) async fn send_request<T>(registration: Registration, request: T) -> R
); );
*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 @@ pub(crate) async fn send_request<T>(registration: Registration, request: T) -> R ...@@ -89,6 +86,8 @@ pub(crate) async fn send_request<T>(registration: Registration, request: T) -> R
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 @@ pub(crate) async fn send_request<T>(registration: Registration, request: T) -> R ...@@ -99,6 +98,6 @@ pub(crate) async fn send_request<T>(registration: Registration, request: T) -> R
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")
}) })
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment