This commit is contained in:
Tangel 2023-10-21 00:06:37 +08:00
parent a5102d0633
commit 5b955f2302
No known key found for this signature in database
GPG key ID: 3EE818DD23597C80
5 changed files with 29 additions and 40 deletions

View file

@ -25,11 +25,12 @@ http = "0.2.9"
sha2 = "0.10.6"
thiserror = "1.0.40"
derive_builder = "0.12.0"
itertools = "0.10.5"
itertools = "0.11.0"
dyn-clone = "1.0.11"
enum_delegate = "0.2.0"
httpdate = "1.0.2"
http-signature-normalization-reqwest = { version = "0.8.0", default-features = false, features = [
http-signature-normalization-reqwest = { version = "0.10.0", default-features = false, features = [
"default-spawner",
"sha-2",
"middleware",
] }
@ -50,14 +51,13 @@ tokio = { version = "1.21.2", features = [
actix-web = { version = "4.3.1", default-features = false, optional = true }
# Axum
axum = { version = "0.6.18", features = [
axum = { git = "https://github.com/tokio-rs/axum.git", features = [
"json",
"headers",
], default-features = false, optional = true }
tower = { version = "0.4.13", optional = true }
hyper = { version = "0.14", optional = true }
futures = "0.3.28"
moka = { version = "0.11.2", features = ["future"] }
tower = { version = "*", optional = true }
hyper = { version = "*", optional = true }
futures = "*"
moka = { version = "0.12.1", features = ["future"] }
[features]
default = ["actix-web", "axum"]
@ -67,14 +67,14 @@ axum = ["dep:axum", "dep:tower", "dep:hyper"]
[dev-dependencies]
rand = "0.8.5"
env_logger = "0.10.0"
tower-http = { version = "0.4.0", features = ["map-request-body", "util"] }
axum = { version = "0.6.18", features = [
tower-http = { version = "*", features = ["map-request-body", "util"] }
axum = { git = "https://github.com/tokio-rs/axum.git", features = [
"http1",
"tokio",
"query",
], default-features = false }
axum-macros = "0.3.7"
tokio = { version = "1.21.2", features = ["full"] }
axum-macros = { git = "https://github.com/tokio-rs/axum.git" }
tokio = { version = "*", features = ["full"] }
[profile.dev]
strip = "symbols"

View file

@ -10,10 +10,8 @@ use axum::{
Router,
};
use error::Error;
use std::{
net::ToSocketAddrs,
sync::{Arc, Mutex},
};
use std::sync::{Arc, Mutex};
use tokio::net::TcpListener;
use tracing::log::{info, LevelFilter};
mod activities;
@ -58,13 +56,8 @@ async fn main() -> Result<(), Error> {
.route("/.well-known/webfinger", get(webfinger))
.layer(FederationMiddleware::new(config));
let addr = BIND_ADDRESS
.to_socket_addrs()?
.next()
.expect("Failed to lookup domain name");
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await?;
let addr = TcpListener::bind(BIND_ADDRESS).await?;
axum::serve(addr, app.into_make_service()).await?;
Ok(())
}

View file

@ -22,7 +22,7 @@ use axum::{
};
use axum_macros::debug_handler;
use serde::Deserialize;
use std::net::ToSocketAddrs;
use std::net::TcpListener;
use tracing::info;
pub fn listen(config: &FederationConfig<DatabaseHandle>) -> Result<(), Error> {
@ -35,11 +35,8 @@ pub fn listen(config: &FederationConfig<DatabaseHandle>) -> Result<(), Error> {
.route("/.well-known/webfinger", get(webfinger))
.layer(FederationMiddleware::new(config));
let addr = hostname
.to_socket_addrs()?
.next()
.expect("Failed to lookup domain name");
let server = axum::Server::bind(&addr).serve(app.into_make_service());
let addr = tokio::net::TcpListener::from_std(TcpListener::bind(hostname)?)?;
let server = axum::serve(addr, app.into_make_service());
tokio::spawn(server);
Ok(())

View file

@ -215,6 +215,7 @@ mod tests {
sync::{atomic::AtomicUsize, Arc},
time::Instant,
};
use tokio::net::TcpListener;
use tracing::info;
use crate::{config::FederationConfig, http_signatures::generate_actor_keypair};
@ -247,10 +248,12 @@ mod tests {
.route("/", post(dodgy_handler))
.with_state(state);
axum::Server::bind(&"0.0.0.0:8001".parse().unwrap())
.serve(app.into_make_service())
.await
.unwrap();
axum::serve(
TcpListener::bind("0.0.0.0:8001").await.unwrap(),
app.into_make_service(),
)
.await
.unwrap();
}
#[tokio::test(flavor = "multi_thread")]

View file

@ -11,7 +11,7 @@ use crate::{
};
use axum::{
async_trait,
body::{Bytes, HttpBody},
body::Body,
extract::FromRequest,
http::{Request, StatusCode},
response::{IntoResponse, Response},
@ -67,17 +67,13 @@ pub struct ActivityData {
}
#[async_trait]
impl<S, B> FromRequest<S, B> for ActivityData
impl<S> FromRequest<S> for ActivityData
where
Bytes: FromRequest<S, B>,
B: HttpBody + Send + 'static,
S: Send + Sync,
<B as HttpBody>::Error: std::fmt::Display,
<B as HttpBody>::Data: Send,
{
type Rejection = Response;
async fn from_request(req: Request<B>, _state: &S) -> Result<Self, Self::Rejection> {
async fn from_request(req: Request<Body>, _state: &S) -> Result<Self, Self::Rejection> {
let (parts, body) = req.into_parts();
// this wont work if the body is an long running stream