Take dev::Payload for inbox which is more flexible

This commit is contained in:
Felix Ableitner 2022-11-14 16:11:36 +01:00
parent aeba7f38bb
commit 11fcb62416
3 changed files with 4 additions and 10 deletions

2
Cargo.lock generated
View file

@ -4,7 +4,7 @@ version = 3
[[package]] [[package]]
name = "activitypub_federation" name = "activitypub_federation"
version = "0.2.3" version = "0.3.0"
dependencies = [ dependencies = [
"activitystreams-kinds", "activitystreams-kinds",
"actix-rt", "actix-rt",

View file

@ -130,7 +130,7 @@ async fn http_post_user_inbox(
let data: InstanceHandle = data.into_inner().deref().clone(); let data: InstanceHandle = data.into_inner().deref().clone();
receive_activity::<WithContext<PersonAcceptedActivities>, MyUser, InstanceHandle>( receive_activity::<WithContext<PersonAcceptedActivities>, MyUser, InstanceHandle>(
request, request,
payload, payload.into_inner(),
&data.clone().local_instance, &data.clone().local_instance,
&Data::new(data), &Data::new(data),
) )

View file

@ -6,12 +6,7 @@ use crate::{
Error, Error,
LocalInstance, LocalInstance,
}; };
use actix_web::{ use actix_web::{dev::Payload, web::Bytes, FromRequest, HttpRequest, HttpResponse};
web::{Bytes, Payload},
FromRequest,
HttpRequest,
HttpResponse,
};
use anyhow::anyhow; use anyhow::anyhow;
use http_signature_normalization_actix::prelude::DigestVerified; use http_signature_normalization_actix::prelude::DigestVerified;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
@ -20,7 +15,7 @@ use tracing::{log::debug, warn};
/// Receive an activity and perform some basic checks, including HTTP signature verification. /// Receive an activity and perform some basic checks, including HTTP signature verification.
pub async fn receive_activity<Activity, ActorT, Datatype>( pub async fn receive_activity<Activity, ActorT, Datatype>(
request: HttpRequest, request: HttpRequest,
payload: Payload, mut payload: Payload,
local_instance: &LocalInstance, local_instance: &LocalInstance,
data: &Data<Datatype>, data: &Data<Datatype>,
) -> Result<HttpResponse, <Activity as ActivityHandler>::Error> ) -> Result<HttpResponse, <Activity as ActivityHandler>::Error>
@ -35,7 +30,6 @@ where
+ From<http_signature_normalization_actix::digest::middleware::VerifyError>, + From<http_signature_normalization_actix::digest::middleware::VerifyError>,
<ActorT as ApubObject>::Error: From<Error> + From<anyhow::Error>, <ActorT as ApubObject>::Error: From<Error> + From<anyhow::Error>,
{ {
let mut payload = payload.into_inner();
// ensure that payload hash was checked against digest header by middleware // ensure that payload hash was checked against digest header by middleware
DigestVerified::from_request(&request, &mut payload).await?; DigestVerified::from_request(&request, &mut payload).await?;