diff --git a/ext_federation/src/ap_client.rs b/ext_federation/src/ap_client.rs index acd1f9b..b02a0fa 100644 --- a/ext_federation/src/ap_client.rs +++ b/ext_federation/src/ap_client.rs @@ -1,6 +1,7 @@ -use std::{fmt::Display, sync::Arc}; +use std::{borrow::Cow, fmt::Display, string::FromUtf8Error, sync::Arc}; use chrono::Utc; +use futures::{FutureExt, TryFutureExt}; use http::{HeaderMap, HeaderName, HeaderValue, Method}; use indexmap::IndexSet; use serde_json::Value; @@ -74,6 +75,8 @@ pub enum ApClientError { SerializerError(#[from] serde_json::Error), #[error("Invalid header value: {0}")] InvalidHeaderValue(#[from] http::header::InvalidHeaderValue), + #[error("UTF-8 parse error: {0}")] + Utf8ParseError(#[from] FromUtf8Error), } trait CreateField { @@ -342,7 +345,7 @@ impl ApClientService for ApClientServiceDefaultProvider { expires: Option>, url: &str, body: &Value, - ) -> Result { + ) -> Result { let url = url.parse()?; let body_bytes = serde_json::to_vec(body)?; let mut sha = sha2::Sha256::new(); @@ -407,12 +410,13 @@ impl ApClientService for ApClientServiceDefaultProvider { .as_ref() .as_ref() .builder(Method::POST, url) - .accept(ContentActivityStreams) .content_type(ContentActivityStreams) .headers(headers) .body(body_bytes) - .json() - .await?) + .send() + .map_ok(String::from_utf8) + .await?? + .to_string()) } } diff --git a/ext_federation/src/lib.rs b/ext_federation/src/lib.rs index 473e0b4..4b0801c 100644 --- a/ext_federation/src/lib.rs +++ b/ext_federation/src/lib.rs @@ -172,5 +172,5 @@ pub trait ApClientService: Send + Sync { expires: Option>, url: &str, body: &Value, - ) -> Result; + ) -> Result; }