Update to actix-web 4.0.0-beta.3

This commit is contained in:
asonix
2021-02-10 18:00:11 -06:00
parent 1c813d917b
commit 43227d9852
12 changed files with 212 additions and 501 deletions
+1 -1
View File
@@ -83,7 +83,7 @@ impl State {
let mut rng = thread_rng();
RSAPrivateKey::new(&mut rng, 4096)
})
.await?;
.await??;
db.update_private_key(&key).await?;
+1 -1
View File
@@ -227,7 +227,7 @@ impl Db {
{
let inner = self.inner.clone();
let t = actix_web::web::block(move || (f)(&inner)).await?;
let t = actix_web::web::block(move || (f)(&inner)).await??;
Ok(t)
}
+5 -11
View File
@@ -131,22 +131,16 @@ impl ResponseError for MyError {
fn error_response(&self) -> HttpResponse {
HttpResponse::build(self.status_code())
.header("Content-Type", "application/activity+json")
.json(serde_json::json!({
.insert_header(("Content-Type", "application/activity+json"))
.json(&serde_json::json!({
"error": self.to_string(),
}))
}
}
impl<T> From<BlockingError<T>> for MyError
where
T: Into<MyError> + Debug,
{
fn from(e: BlockingError<T>) -> Self {
match e {
BlockingError::Error(e) => e.into(),
BlockingError::Canceled => MyError::Canceled,
}
impl From<BlockingError> for MyError {
fn from(_: BlockingError) -> Self {
MyError::Canceled
}
}
+6 -8
View File
@@ -32,13 +32,12 @@ impl ResponseError for DebugError {
}
}
impl<S> Transform<S> for DebugPayload
impl<S> Transform<S, ServiceRequest> for DebugPayload
where
S: Service<Request = ServiceRequest, Error = actix_web::Error>,
S: Service<ServiceRequest, Error = actix_web::Error>,
S::Future: 'static,
S::Error: 'static,
{
type Request = S::Request;
type Response = S::Response;
type Error = S::Error;
type InitError = ();
@@ -50,22 +49,21 @@ where
}
}
impl<S> Service for DebugPayloadMiddleware<S>
impl<S> Service<ServiceRequest> for DebugPayloadMiddleware<S>
where
S: Service<Request = ServiceRequest, Error = actix_web::Error>,
S: Service<ServiceRequest, Error = actix_web::Error>,
S::Future: 'static,
S::Error: 'static,
{
type Request = S::Request;
type Response = S::Response;
type Error = S::Error;
type Future = LocalBoxFuture<'static, Result<S::Response, S::Error>>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.1.poll_ready(cx)
}
fn call(&mut self, mut req: S::Request) -> Self::Future {
fn call(&self, mut req: ServiceRequest) -> Self::Future {
if self.0 && req.method() == Method::POST {
let pl = req.take_payload();
req.set_payload(Payload::Stream(Box::pin(once(
+1 -1
View File
@@ -124,7 +124,7 @@ async fn do_verify(
Ok(()) as Result<(), MyError>
})
.await?;
.await??;
Ok(())
}
+7 -7
View File
@@ -219,8 +219,8 @@ impl Requests {
let client: Client = self.client.borrow().clone();
let res = client
.get(url)
.header("Accept", accept)
.set(Date(SystemTime::now().into()))
.insert_header(("Accept", accept))
.insert_header(Date(SystemTime::now().into()))
.signature(
self.config.clone(),
self.key_id.clone(),
@@ -276,8 +276,8 @@ impl Requests {
let client: Client = self.client.borrow().clone();
let res = client
.get(url)
.header("Accept", "*/*")
.set(Date(SystemTime::now().into()))
.insert_header(("Accept", "*/*"))
.insert_header(Date(SystemTime::now().into()))
.signature(
self.config.clone(),
self.key_id.clone(),
@@ -346,9 +346,9 @@ impl Requests {
let client: Client = self.client.borrow().clone();
let res = client
.post(inbox.as_str())
.header("Accept", "application/activity+json")
.header("Content-Type", "application/activity+json")
.set(Date(SystemTime::now().into()))
.insert_header(("Accept", "application/activity+json"))
.insert_header(("Content-Type", "application/activity+json"))
.insert_header(Date(SystemTime::now().into()))
.signature_with_digest(
self.config.clone(),
self.key_id.clone(),
+1 -1
View File
@@ -31,7 +31,7 @@ pub(crate) async fn route(
fn cached(content_type: String, bytes: web::Bytes) -> HttpResponse {
HttpResponse::Ok()
.set(CacheControl(vec![
.insert_header(CacheControl(vec![
CacheDirective::Public,
CacheDirective::MaxAge(60 * 60 * 24),
CacheDirective::Extension("immutable".to_owned(), None),
+2 -2
View File
@@ -23,7 +23,7 @@ fn ok<T>(item: T) -> HttpResponse
where
T: Serialize,
{
HttpResponse::Ok().content_type(CONTENT_TYPE).json(item)
HttpResponse::Ok().content_type(CONTENT_TYPE).json(&item)
}
fn accepted<T>(item: T) -> HttpResponse
@@ -32,5 +32,5 @@ where
{
HttpResponse::Accepted()
.content_type(CONTENT_TYPE)
.json(item)
.json(&item)
}
+1 -1
View File
@@ -14,7 +14,7 @@ pub(crate) async fn well_known(config: web::Data<Config>) -> impl Responder {
kind: None,
}],
})
.with_header("Content-Type", "application/jrd+json")
.with_header(("Content-Type", "application/jrd+json"))
}
#[derive(serde::Serialize)]
+2 -2
View File
@@ -7,12 +7,12 @@ use actix_web::{
pub(crate) async fn route(filename: web::Path<String>) -> HttpResponse {
if let Some(data) = StaticFile::get(&filename.into_inner()) {
HttpResponse::Ok()
.set(CacheControl(vec![
.insert_header(CacheControl(vec![
CacheDirective::Public,
CacheDirective::MaxAge(60 * 60 * 24),
CacheDirective::Extension("immutable".to_owned(), None),
]))
.set(ContentType(data.mime.clone()))
.insert_header(ContentType(data.mime.clone()))
.body(data.content)
} else {
HttpResponse::NotFound()