Build client for every inbox in broadcast()
This commit is contained in:
parent
ac48744aca
commit
24c9c7b5a1
@ -132,14 +132,6 @@ where
|
|||||||
|
|
||||||
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");
|
||||||
let client = if let Some(proxy) = proxy {
|
|
||||||
ClientBuilder::new().proxy(proxy)
|
|
||||||
} else {
|
|
||||||
ClientBuilder::new()
|
|
||||||
}
|
|
||||||
.connect_timeout(std::time::Duration::from_secs(5))
|
|
||||||
.build()
|
|
||||||
.expect("Can't build client");
|
|
||||||
for inbox in boxes {
|
for inbox in boxes {
|
||||||
let body = signed.to_string();
|
let body = signed.to_string();
|
||||||
let mut headers = request::headers();
|
let mut headers = request::headers();
|
||||||
@ -161,22 +153,33 @@ 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(
|
||||||
client
|
if let Some(proxy) = proxy.clone() {
|
||||||
.post(&inbox)
|
ClientBuilder::new().proxy(proxy)
|
||||||
.headers(headers.clone())
|
} else {
|
||||||
.header(
|
ClientBuilder::new()
|
||||||
"Signature",
|
}
|
||||||
request::signature(sender, &headers, ("post", url.path(), url.query()))
|
.connect_timeout(std::time::Duration::from_secs(5))
|
||||||
.expect("activity_pub::broadcast: request signature error"),
|
.build()
|
||||||
)
|
.expect("Can't build client")
|
||||||
.body(body)
|
.post(&inbox)
|
||||||
.send()
|
.headers(headers.clone())
|
||||||
.and_then(|r| r.into_body().concat2())
|
.header(
|
||||||
.map(move |response| {
|
"Signature",
|
||||||
debug!("Successfully sent activity to inbox ({})", inbox);
|
request::signature(sender, &headers, ("post", url.path(), url.query()))
|
||||||
debug!("Response: \"{:?}\"\n", response)
|
.expect("activity_pub::broadcast: request signature error"),
|
||||||
})
|
)
|
||||||
.map_err(|e| warn!("Error while sending to inbox ({:?})", e)),
|
.body(body)
|
||||||
|
.send()
|
||||||
|
.and_then(move |r| {
|
||||||
|
if r.status().is_success() {
|
||||||
|
debug!("Successfully sent activity to inbox ({})", &inbox);
|
||||||
|
} else {
|
||||||
|
warn!("Error while sending to inbox ({:?})", &r)
|
||||||
|
}
|
||||||
|
r.into_body().concat2()
|
||||||
|
})
|
||||||
|
.map(move |response| debug!("Response: \"{:?}\"\n", response))
|
||||||
|
.map_err(|e| warn!("Error while sending to inbox ({:?})", e)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
rt.run().unwrap();
|
rt.run().unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user