plume-common: also make requests async
This commit is contained in:
parent
75722abc9e
commit
fd9764ff17
@ -3,7 +3,7 @@ use array_tool::vec::Uniq;
|
||||
use reqwest::r#async::ClientBuilder;
|
||||
use rocket::{
|
||||
http::Status,
|
||||
request::{FromRequest, Request},
|
||||
request::{FromRequestFuture, FromRequestAsync, Request},
|
||||
response::{Responder, Response, ResultFuture},
|
||||
Outcome,
|
||||
};
|
||||
@ -84,10 +84,11 @@ impl<'r, O: Object + Send + 'r> Responder<'r> for ActivityStream<O> {
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ApRequest;
|
||||
impl<'a, 'r> FromRequest<'a, 'r> for ApRequest {
|
||||
impl<'a, 'r> FromRequestAsync<'a, 'r> for ApRequest {
|
||||
type Error = ();
|
||||
|
||||
fn from_request(request: &'a Request<'r>) -> Outcome<Self, (Status, Self::Error), ()> {
|
||||
fn from_request(request: &'a Request<'r>) -> FromRequestFuture<'a, Self, Self::Error> {
|
||||
Box::pin(async move {
|
||||
request
|
||||
.headers()
|
||||
.get_one("Accept")
|
||||
@ -95,7 +96,8 @@ impl<'a, 'r> FromRequest<'a, 'r> for ApRequest {
|
||||
header
|
||||
.split(',')
|
||||
.map(|ct| match ct.trim() {
|
||||
// bool for Forward: true if found a valid Content-Type for Plume first (HTML), false otherwise
|
||||
// bool for Forward: true if found a valid Content-Type for Plume first (HTML),
|
||||
// false otherwise
|
||||
"application/ld+json; profile=\"https://w3.org/ns/activitystreams\""
|
||||
| "application/ld+json;profile=\"https://w3.org/ns/activitystreams\""
|
||||
| "application/activity+json"
|
||||
@ -113,6 +115,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for ApRequest {
|
||||
.map_forward(|_| ())
|
||||
})
|
||||
.unwrap_or(Outcome::Forward(()))
|
||||
})
|
||||
}
|
||||
}
|
||||
pub fn broadcast<S, A, T, C>(sender: &S, act: A, to: Vec<T>)
|
||||
|
Loading…
Reference in New Issue
Block a user