mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-12-23 18:40:34 +00:00
Reuse reqwest client on broadcasting
See https://users.rust-lang.org/t/reqwest-http-client-fails-when-too-much-concurrency/55644/2
This commit is contained in:
parent
ef57ef91f0
commit
db0f1a3c46
1 changed files with 28 additions and 27 deletions
|
@ -132,6 +132,14 @@ where
|
||||||
.sign(sender)
|
.sign(sender)
|
||||||
.expect("activity_pub::broadcast: signature error");
|
.expect("activity_pub::broadcast: signature error");
|
||||||
|
|
||||||
|
let client = if let Some(proxy) = proxy.clone() {
|
||||||
|
ClientBuilder::new().proxy(proxy)
|
||||||
|
} else {
|
||||||
|
ClientBuilder::new()
|
||||||
|
}
|
||||||
|
.connect_timeout(std::time::Duration::from_secs(5))
|
||||||
|
.build()
|
||||||
|
.expect("Can't build client");
|
||||||
let mut rt = tokio::runtime::current_thread::Runtime::new()
|
let mut rt = tokio::runtime::current_thread::Runtime::new()
|
||||||
.expect("Error while initializing tokio runtime for federation");
|
.expect("Error while initializing tokio runtime for federation");
|
||||||
for inbox in boxes {
|
for inbox in boxes {
|
||||||
|
@ -155,14 +163,7 @@ where
|
||||||
headers.insert("Host", host_header_value.unwrap());
|
headers.insert("Host", host_header_value.unwrap());
|
||||||
headers.insert("Digest", request::Digest::digest(&body));
|
headers.insert("Digest", request::Digest::digest(&body));
|
||||||
rt.spawn(
|
rt.spawn(
|
||||||
if let Some(proxy) = proxy.clone() {
|
client
|
||||||
ClientBuilder::new().proxy(proxy)
|
|
||||||
} else {
|
|
||||||
ClientBuilder::new()
|
|
||||||
}
|
|
||||||
.connect_timeout(std::time::Duration::from_secs(5))
|
|
||||||
.build()
|
|
||||||
.expect("Can't build client")
|
|
||||||
.post(&inbox)
|
.post(&inbox)
|
||||||
.headers(headers.clone())
|
.headers(headers.clone())
|
||||||
.header(
|
.header(
|
||||||
|
|
Loading…
Reference in a new issue