Add a ApRequest request guard to accept multiple ActivityPub header on one route
This commit is contained in:
parent
3796aa48c2
commit
8e47219d82
|
@ -2,9 +2,10 @@ use activitypub::{Activity, Actor, Object, Link};
|
|||
use array_tool::vec::Uniq;
|
||||
use reqwest::Client;
|
||||
use rocket::{
|
||||
Outcome,
|
||||
http::Status,
|
||||
response::{Response, Responder},
|
||||
request::Request
|
||||
request::{FromRequest, Request}
|
||||
};
|
||||
use serde_json;
|
||||
|
||||
|
@ -59,6 +60,25 @@ impl<'r, O: Object> Responder<'r> for ActivityStream<O> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct ApRequest;
|
||||
impl<'a, 'r> FromRequest<'a, 'r> for ApRequest {
|
||||
type Error = ();
|
||||
|
||||
fn from_request(request: &'a Request<'r>) -> Outcome<Self, (Status, Self::Error), ()> {
|
||||
request.headers().get_one("Content-Type").map(|header| header.split(",").map(|ct| match ct {
|
||||
"application/ld+json; profile=\"w3.org/ns/activitystreams\"" |
|
||||
"application/ld+json;profile=\"w3.org/ns/activitystreams\"" |
|
||||
"application/activity+json" |
|
||||
"application/ld+json" => Outcome::Success(ApRequest),
|
||||
_ => Outcome::Forward(())
|
||||
}).fold(Outcome::Forward(()), |out, ct| if out.is_success() {
|
||||
out
|
||||
} else {
|
||||
ct
|
||||
})).unwrap_or(Outcome::Forward(()))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn broadcast<A: Activity, S: sign::Signer, T: inbox::WithInbox + Actor>(sender: &S, act: A, to: Vec<T>) {
|
||||
let boxes = to.into_iter()
|
||||
.map(|u| u.get_shared_inbox_url().unwrap_or(u.get_inbox_url()))
|
||||
|
|
Loading…
Reference in New Issue