mirror of
https://github.com/LemmyNet/activitypub-federation-rust.git
synced 2025-05-20 01:18:52 +00:00
add timeout, comment
This commit is contained in:
parent
7f2c303c36
commit
c8212cac1a
1 changed files with 10 additions and 3 deletions
|
@ -59,9 +59,13 @@ pub struct FederationConfig<T: Clone> {
|
||||||
#[builder(default = "20")]
|
#[builder(default = "20")]
|
||||||
pub(crate) http_fetch_limit: u32,
|
pub(crate) http_fetch_limit: u32,
|
||||||
#[builder(default = "default_client()")]
|
#[builder(default = "default_client()")]
|
||||||
/// HTTP client used for all outgoing requests. Middleware can be used to add functionality
|
/// HTTP client used for all outgoing requests. When passing a custom client here you should
|
||||||
/// like log tracing or retry of failed requests.
|
/// also disable redirects and set timeouts.
|
||||||
/// Redirects should be disabled to prevent an attacker from accessing local addresses.
|
///
|
||||||
|
/// Middleware can be used to add functionality like log tracing or retry of failed requests.
|
||||||
|
/// Redirects are disabled by default, because automatic redirect URLs can't be validated.
|
||||||
|
/// Instead a single redirect is handled manually. The default client sets a timeout of 10s
|
||||||
|
/// to avoid excessive resource usage when connecting to dead servers.
|
||||||
pub(crate) client: ClientWithMiddleware,
|
pub(crate) client: ClientWithMiddleware,
|
||||||
/// Run library in debug mode. This allows usage of http and localhost urls. It also sends
|
/// Run library in debug mode. This allows usage of http and localhost urls. It also sends
|
||||||
/// outgoing activities synchronously, not in background thread. This helps to make tests
|
/// outgoing activities synchronously, not in background thread. This helps to make tests
|
||||||
|
@ -418,8 +422,11 @@ impl<T: Clone> FederationMiddleware<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_client() -> ClientWithMiddleware {
|
fn default_client() -> ClientWithMiddleware {
|
||||||
|
let timeout = Duration::from_secs(10);
|
||||||
Client::builder()
|
Client::builder()
|
||||||
.redirect(Policy::none())
|
.redirect(Policy::none())
|
||||||
|
.timeout(timeout)
|
||||||
|
.connect_timeout(timeout)
|
||||||
.build()
|
.build()
|
||||||
.unwrap_or_else(|_| Client::default())
|
.unwrap_or_else(|_| Client::default())
|
||||||
.into()
|
.into()
|
||||||
|
|
Loading…
Reference in a new issue