mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-01-28 03:35:55 +03:00
fix: do not expect that all http requests are valid reqwest requests
This commit is contained in:
parent
7aa70e2030
commit
3ce3d13378
5 changed files with 28 additions and 30 deletions
|
@ -13,11 +13,16 @@ use tracing::warn;
|
||||||
pub(crate) async fn send_request<T: OutgoingRequest>(
|
pub(crate) async fn send_request<T: OutgoingRequest>(
|
||||||
registration: Registration,
|
registration: Registration,
|
||||||
request: T,
|
request: T,
|
||||||
) -> Option<Result<T::IncomingResponse>>
|
) -> Result<Option<T::IncomingResponse>>
|
||||||
where
|
where
|
||||||
T: Debug,
|
T: Debug,
|
||||||
{
|
{
|
||||||
let destination = registration.url?;
|
let destination = match registration.url {
|
||||||
|
Some(url) => url,
|
||||||
|
None => {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let hs_token = registration.hs_token.as_str();
|
let hs_token = registration.hs_token.as_str();
|
||||||
|
|
||||||
|
@ -45,8 +50,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 mut reqwest_request = reqwest::Request::try_from(http_request)?;
|
||||||
.expect("all http requests are valid reqwest requests");
|
|
||||||
|
|
||||||
*reqwest_request.timeout_mut() = Some(Duration::from_secs(30));
|
*reqwest_request.timeout_mut() = Some(Duration::from_secs(30));
|
||||||
|
|
||||||
|
@ -63,7 +67,7 @@ where
|
||||||
"Could not send request to appservice {:?} at {}: {}",
|
"Could not send request to appservice {:?} at {}: {}",
|
||||||
registration.id, destination, e
|
registration.id, destination, e
|
||||||
);
|
);
|
||||||
return Some(Err(e.into()));
|
return Err(e.into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -100,11 +104,11 @@ where
|
||||||
.expect("reqwest body is valid http body"),
|
.expect("reqwest body is valid http body"),
|
||||||
);
|
);
|
||||||
|
|
||||||
Some(response.map_err(|_| {
|
response.map(Some).map_err(|_| {
|
||||||
warn!(
|
warn!(
|
||||||
"Appservice returned invalid response bytes {}\n{}",
|
"Appservice returned invalid response bytes {}\n{}",
|
||||||
destination, url
|
destination, url
|
||||||
);
|
);
|
||||||
Error::BadServerResponse("Server returned bad response.")
|
Error::BadServerResponse("Server returned bad response.")
|
||||||
}))
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,20 +102,18 @@ pub(crate) async fn get_alias_helper(
|
||||||
None => {
|
None => {
|
||||||
for appservice in services().appservice.read().await.values() {
|
for appservice in services().appservice.read().await.values() {
|
||||||
if appservice.aliases.is_match(room_alias.as_str())
|
if appservice.aliases.is_match(room_alias.as_str())
|
||||||
&& if let Some(opt_result) = services()
|
&& matches!(
|
||||||
.sending
|
services()
|
||||||
.send_appservice_request(
|
.sending
|
||||||
appservice.registration.clone(),
|
.send_appservice_request(
|
||||||
appservice::query::query_room_alias::v1::Request {
|
appservice.registration.clone(),
|
||||||
room_alias: room_alias.clone(),
|
appservice::query::query_room_alias::v1::Request {
|
||||||
},
|
room_alias: room_alias.clone(),
|
||||||
)
|
},
|
||||||
.await
|
)
|
||||||
{
|
.await,
|
||||||
opt_result.is_ok()
|
Ok(Some(_opt_result))
|
||||||
} else {
|
)
|
||||||
false
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
room_id = Some(
|
room_id = Some(
|
||||||
services()
|
services()
|
||||||
|
|
|
@ -233,8 +233,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let reqwest_request = reqwest::Request::try_from(http_request)
|
let reqwest_request = reqwest::Request::try_from(http_request)?;
|
||||||
.expect("all http requests are valid reqwest requests");
|
|
||||||
|
|
||||||
let url = reqwest_request.url().clone();
|
let url = reqwest_request.url().clone();
|
||||||
|
|
||||||
|
|
|
@ -66,8 +66,7 @@ impl Service {
|
||||||
})?
|
})?
|
||||||
.map(|body| body.freeze());
|
.map(|body| body.freeze());
|
||||||
|
|
||||||
let reqwest_request = reqwest::Request::try_from(http_request)
|
let reqwest_request = reqwest::Request::try_from(http_request)?;
|
||||||
.expect("all http requests are valid reqwest requests");
|
|
||||||
|
|
||||||
// TODO: we could keep this very short and let expo backoff do it's thing...
|
// TODO: we could keep this very short and let expo backoff do it's thing...
|
||||||
//*reqwest_request.timeout_mut() = Some(Duration::from_secs(5));
|
//*reqwest_request.timeout_mut() = Some(Duration::from_secs(5));
|
||||||
|
|
|
@ -512,10 +512,8 @@ impl Service {
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
None => Ok(kind.clone()),
|
Ok(_) => Ok(kind.clone()),
|
||||||
Some(op_resp) => op_resp
|
Err(e) => Err((kind.clone(), e)),
|
||||||
.map(|_response| kind.clone())
|
|
||||||
.map_err(|e| (kind.clone(), e)),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
drop(permit);
|
drop(permit);
|
||||||
|
@ -710,7 +708,7 @@ impl Service {
|
||||||
&self,
|
&self,
|
||||||
registration: Registration,
|
registration: Registration,
|
||||||
request: T,
|
request: T,
|
||||||
) -> Option<Result<T::IncomingResponse>>
|
) -> Result<Option<T::IncomingResponse>>
|
||||||
where
|
where
|
||||||
T: Debug,
|
T: Debug,
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue