convert plume-common to rocket async
it only took 3 hours of @jebrosen's patient help.
This commit is contained in:
parent
bb5c2b69a7
commit
ec9b699c6e
@ -4,7 +4,7 @@ use reqwest::r#async::ClientBuilder;
|
|||||||
use rocket::{
|
use rocket::{
|
||||||
http::Status,
|
http::Status,
|
||||||
request::{FromRequest, Request},
|
request::{FromRequest, Request},
|
||||||
response::{Responder, Response},
|
response::{Responder, Response, ResultFuture},
|
||||||
Outcome,
|
Outcome,
|
||||||
};
|
};
|
||||||
use serde_json;
|
use serde_json;
|
||||||
@ -63,14 +63,21 @@ impl<T> ActivityStream<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'r, O: Object> Responder<'r> for ActivityStream<O> {
|
impl<'r, O: Object + Send + 'r> Responder<'r> for ActivityStream<O> {
|
||||||
fn respond_to(self, request: &Request<'_>) -> Result<Response<'r>, Status> {
|
fn respond_to(self, request: &'r Request<'_>) -> ResultFuture<'r> {
|
||||||
let mut json = serde_json::to_value(&self.0).map_err(|_| Status::InternalServerError)?;
|
Box::pin(async move {
|
||||||
json["@context"] = context();
|
let mut json = serde_json::to_value(&self.0).map_err(|_| Status::InternalServerError)?;
|
||||||
serde_json::to_string(&json).respond_to(request).map(|r| {
|
json["@context"] = context();
|
||||||
Response::build_from(r)
|
let result = serde_json::to_string(&json).map_err(rocket::response::Debug);
|
||||||
.raw_header("Content-Type", "application/activity+json")
|
match result.respond_to(request).await {
|
||||||
.finalize()
|
Ok(r) => {
|
||||||
|
Response::build_from(r)
|
||||||
|
.raw_header("Content-Type", "application/activity+json")
|
||||||
|
.ok()
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
Err(e) => Err(e),
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user