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 reqwest::r#async::ClientBuilder;
|
||||||
use rocket::{
|
use rocket::{
|
||||||
http::Status,
|
http::Status,
|
||||||
request::{FromRequest, Request},
|
request::{FromRequestFuture, FromRequestAsync, Request},
|
||||||
response::{Responder, Response, ResultFuture},
|
response::{Responder, Response, ResultFuture},
|
||||||
Outcome,
|
Outcome,
|
||||||
};
|
};
|
||||||
@ -84,10 +84,11 @@ impl<'r, O: Object + Send + 'r> Responder<'r> for ActivityStream<O> {
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ApRequest;
|
pub struct ApRequest;
|
||||||
impl<'a, 'r> FromRequest<'a, 'r> for ApRequest {
|
impl<'a, 'r> FromRequestAsync<'a, 'r> for ApRequest {
|
||||||
type Error = ();
|
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
|
request
|
||||||
.headers()
|
.headers()
|
||||||
.get_one("Accept")
|
.get_one("Accept")
|
||||||
@ -95,7 +96,8 @@ impl<'a, 'r> FromRequest<'a, 'r> for ApRequest {
|
|||||||
header
|
header
|
||||||
.split(',')
|
.split(',')
|
||||||
.map(|ct| match ct.trim() {
|
.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/ld+json;profile=\"https://w3.org/ns/activitystreams\""
|
| "application/ld+json;profile=\"https://w3.org/ns/activitystreams\""
|
||||||
| "application/activity+json"
|
| "application/activity+json"
|
||||||
@ -113,6 +115,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for ApRequest {
|
|||||||
.map_forward(|_| ())
|
.map_forward(|_| ())
|
||||||
})
|
})
|
||||||
.unwrap_or(Outcome::Forward(()))
|
.unwrap_or(Outcome::Forward(()))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn broadcast<S, A, T, C>(sender: &S, act: A, to: Vec<T>)
|
pub fn broadcast<S, A, T, C>(sender: &S, act: A, to: Vec<T>)
|
||||||
|
Loading…
Reference in New Issue
Block a user