From 7b4a30f30a23b36df1e5441cb7eb7f00abaeed47 Mon Sep 17 00:00:00 2001 From: Tangel Date: Fri, 4 Oct 2024 14:18:50 +0800 Subject: [PATCH] update --- .gitignore | 2 ++ Cargo.toml | 14 +++++++------- src/actix_web/inbox.rs | 10 ++++++---- src/actix_web/mod.rs | 10 ++++++---- src/axum/inbox.rs | 2 -- src/axum/middleware.rs | 3 +-- src/fetch/object_id.rs | 1 + src/http_signatures.rs | 1 + 8 files changed, 24 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index b10a717..7ad749a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ flamegraph.svg # nix flake /flake.nix /flake.lock + +.vscode \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 2dbb3e3..6538b94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ tracing = "0.1.40" base64 = "0.22.1" rand = "0.8.5" rsa = "0.9.6" -once_cell = "1.19.0" +once_cell = "1.20.1" http = "1.1.0" sha2 = { version = "0.10.8", features = ["oid"] } thiserror = "1.0.63" @@ -63,15 +63,15 @@ http-signature-normalization-reqwest = { version = "0.12.0", default-features = "default-spawner", ] } http-signature-normalization = "0.7.0" -bytes = "1.6.1" +bytes = "1.7.2" futures-core = { version = "0.3.30", default-features = false } pin-project-lite = "0.2.14" activitystreams-kinds = "0.3.0" -regex = { version = "1.10.5", default-features = false, features = [ +regex = { version = "1.11.0", default-features = false, features = [ "std", "unicode", ] } -tokio = { version = "1.38.0", features = [ +tokio = { version = "1.40.0", features = [ "sync", "rt", "rt-multi-thread", @@ -90,21 +90,21 @@ actix-web = { version = "4.8.0", default-features = false, optional = true } axum = { git = "https://github.com/tokio-rs/axum.git", features = [ "json", ], default-features = false, optional = true } -tower = { version = "0.4.13", optional = true } +tower = { version = "0.5.1", optional = true } hyper = { version = "1.4.1", optional = true } http-body-util = { version = "0.1.2", optional = true } [dev-dependencies] anyhow = "1.0.86" env_logger = "0.11.3" -tower-http = { version = "0.5.2", features = ["map-request-body", "util"] } +tower-http = { version = "0.6.1", features = ["map-request-body", "util"] } axum = { git = "https://github.com/tokio-rs/axum.git", features = [ "http1", "tokio", "query", ], default-features = false } axum-macros = { git = "https://github.com/tokio-rs/axum.git" } -tokio = { version = "1.38.1", features = ["full"] } +tokio = { version = "1.40.0", features = ["full"] } [profile.dev] strip = "symbols" diff --git a/src/actix_web/inbox.rs b/src/actix_web/inbox.rs index f0d776d..cf7fab5 100644 --- a/src/actix_web/inbox.rs +++ b/src/actix_web/inbox.rs @@ -32,15 +32,16 @@ where .headers() .get("Digest") .map(|v| reqwest::header::HeaderValue::from_str(v.to_str().unwrap_or_default())) - .and_then(|v| v.ok()); + .and_then(std::result::Result::ok); verify_body_hash(header_value.as_ref(), &body)?; let (activity, actor) = parse_received_activity::(&body, data).await?; let mut vec = Vec::<(_, _)>::with_capacity(request.headers().len()); request.headers().iter().for_each(|(k, v)| { - let k = reqwest::header::HeaderName::from_str(k.as_str()).unwrap(); - let v = reqwest::header::HeaderValue::from_str(v.to_str().unwrap_or_default()).unwrap(); + let k = reqwest::header::HeaderName::from_str(k.as_str()).expect("Failed to parse header"); + let v = reqwest::header::HeaderValue::from_str(v.to_str().unwrap_or_default()) + .expect("Failed to parse header"); vec.push((k, v)); }); let headers = vec.iter().map(|(k, v)| (k, v)).collect::>(); @@ -49,7 +50,8 @@ where headers, &reqwest::Method::from_str(request.method().as_str()) .map_err(|err| Error::Other(err.to_string()))?, - &http::Uri::from_str(&request.uri().to_string()).unwrap(), + &http::Uri::from_str(&request.uri().to_string()) + .map_err(|err| Error::Other(err.to_string()))?, actor.public_key_pem(), )?; diff --git a/src/actix_web/mod.rs b/src/actix_web/mod.rs index 5524112..918fa0b 100644 --- a/src/actix_web/mod.rs +++ b/src/actix_web/mod.rs @@ -30,13 +30,14 @@ where .headers() .get("Digest") .map(|v| reqwest::header::HeaderValue::from_str(v.to_str().unwrap_or_default())) - .and_then(|v| v.ok()); + .and_then(std::result::Result::ok); verify_body_hash(header_value.as_ref(), &body.unwrap_or_default())?; let mut vec = Vec::<(_, _)>::with_capacity(request.headers().len()); request.headers().iter().for_each(|(k, v)| { - let k = reqwest::header::HeaderName::from_str(k.as_str()).unwrap(); - let v = reqwest::header::HeaderValue::from_str(v.to_str().unwrap_or_default()).unwrap(); + let k = reqwest::header::HeaderName::from_str(k.as_str()).expect("Failed to parse header"); + let v = reqwest::header::HeaderValue::from_str(v.to_str().unwrap_or_default()) + .expect("Failed to parse header"); vec.push((k, v)); }); let headers = vec.iter().map(|(k, v)| (k, v)).collect::>(); @@ -45,7 +46,8 @@ where headers, &reqwest::Method::from_str(request.method().as_str()) .map_err(|err| Error::Other(err.to_string()))?, - &http::Uri::from_str(&request.uri().to_string()).unwrap(), + &http::Uri::from_str(&request.uri().to_string()) + .map_err(|err| Error::Other(err.to_string()))?, data, ) .await diff --git a/src/axum/inbox.rs b/src/axum/inbox.rs index 430d790..f230516 100644 --- a/src/axum/inbox.rs +++ b/src/axum/inbox.rs @@ -10,7 +10,6 @@ use crate::{ traits::{ActivityHandler, Actor, Object}, }; use axum::{ - async_trait, extract::{FromRequest, Request}, http::StatusCode, response::{IntoResponse, Response}, @@ -58,7 +57,6 @@ pub struct ActivityData { body: Vec, } -#[async_trait] impl FromRequest for ActivityData where S: Send + Sync, diff --git a/src/axum/middleware.rs b/src/axum/middleware.rs index 290dc94..2f8b0e9 100644 --- a/src/axum/middleware.rs +++ b/src/axum/middleware.rs @@ -1,5 +1,5 @@ use crate::config::{Data, FederationConfig, FederationMiddleware}; -use axum::{async_trait, body::Body, extract::FromRequestParts, http::Request, response::Response}; +use axum::{body::Body, extract::FromRequestParts, http::Request, response::Response}; use http::{request::Parts, StatusCode}; use std::task::{Context, Poll}; use tower::{Layer, Service}; @@ -43,7 +43,6 @@ where } } -#[async_trait] impl FromRequestParts for Data where S: Send + Sync, diff --git a/src/fetch/object_id.rs b/src/fetch/object_id.rs index ce52c43..7d9452c 100644 --- a/src/fetch/object_id.rs +++ b/src/fetch/object_id.rs @@ -345,6 +345,7 @@ const _IMPL_DIESEL_NEW_TYPE_FOR_OBJECT_ID: () = { #[cfg(test)] #[allow(clippy::unwrap_used)] +#[allow(missing_docs)] pub mod tests { use super::*; use crate::traits::tests::DbUser; diff --git a/src/http_signatures.rs b/src/http_signatures.rs index d6d1919..0094829 100644 --- a/src/http_signatures.rs +++ b/src/http_signatures.rs @@ -283,6 +283,7 @@ pub(crate) fn verify_body_hash( #[cfg(test)] #[allow(clippy::unwrap_used)] +#[allow(missing_docs)] pub mod test { use super::*; use crate::activity_sending::generate_request_headers;