mirror of
https://github.com/LemmyNet/activitypub-federation-rust.git
synced 2024-06-02 13:29:36 +00:00
Minor refactoring
This commit is contained in:
parent
12aad8bf3c
commit
48489eb265
|
@ -16,16 +16,12 @@ use futures::StreamExt;
|
||||||
use httpdate::fmt_http_date;
|
use httpdate::fmt_http_date;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use openssl::pkey::{PKey, Private};
|
use openssl::pkey::{PKey, Private};
|
||||||
use reqwest::{
|
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
|
||||||
header::{HeaderMap, HeaderName, HeaderValue},
|
|
||||||
Request,
|
|
||||||
};
|
|
||||||
use reqwest_middleware::ClientWithMiddleware;
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::{
|
use std::{
|
||||||
self,
|
self,
|
||||||
fmt::{Debug, Display},
|
fmt::{Debug, Display},
|
||||||
time::{Duration, SystemTime},
|
time::SystemTime,
|
||||||
};
|
};
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -95,34 +91,20 @@ impl SendActivityTask<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// convert a sendactivitydata to a request, signing and sending it
|
/// convert a sendactivitydata to a request, signing and sending it
|
||||||
pub async fn sign_and_send<Datatype: Clone>(&self, data: &Data<Datatype>) -> Result<(), Error> {
|
pub async fn sign_and_send<Datatype: Clone>(self, data: &Data<Datatype>) -> Result<(), Error> {
|
||||||
let req = self
|
let client = &data.config.client;
|
||||||
.sign(&data.config.client, data.config.request_timeout)
|
|
||||||
.await?;
|
|
||||||
self.send(&data.config.client, req).await
|
|
||||||
}
|
|
||||||
async fn sign(
|
|
||||||
&self,
|
|
||||||
client: &ClientWithMiddleware,
|
|
||||||
timeout: Duration,
|
|
||||||
) -> Result<Request, Error> {
|
|
||||||
let task = self;
|
|
||||||
let request_builder = client
|
let request_builder = client
|
||||||
.post(task.inbox.to_string())
|
.post(self.inbox.to_string())
|
||||||
.timeout(timeout)
|
.timeout(data.config.request_timeout)
|
||||||
.headers(generate_request_headers(&task.inbox));
|
.headers(generate_request_headers(&self.inbox));
|
||||||
let request = sign_request(
|
let request = sign_request(
|
||||||
request_builder,
|
request_builder,
|
||||||
task.actor_id,
|
self.actor_id,
|
||||||
task.activity.clone(),
|
self.activity.clone(),
|
||||||
task.private_key.clone(),
|
self.private_key.clone(),
|
||||||
task.http_signature_compat,
|
self.http_signature_compat,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(request)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn send(&self, client: &ClientWithMiddleware, request: Request) -> Result<(), Error> {
|
|
||||||
let response = client.execute(request).await?;
|
let response = client.execute(request).await?;
|
||||||
|
|
||||||
match response {
|
match response {
|
||||||
|
@ -286,7 +268,7 @@ mod tests {
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
|
|
||||||
for _ in 0..num_messages {
|
for _ in 0..num_messages {
|
||||||
message.sign_and_send(&data).await?;
|
message.clone().sign_and_send(&data).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Queue Sent: {:?}", start.elapsed());
|
info!("Queue Sent: {:?}", start.elapsed());
|
||||||
|
|
Loading…
Reference in a new issue