From 87d26e69ed59a62da2d53ce30527ebfc267f4534 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Mon, 28 Apr 2025 22:39:32 +0100 Subject: [PATCH 1/2] chore: Migrate to axum 0.8 Co-authored-by: dasha_uwu --- Cargo.lock | 79 +++++++++++++++++++++++++++++++------- Cargo.toml | 6 +-- src/api/client/unstable.rs | 6 +-- src/api/router.rs | 32 +++++++-------- src/api/router/args.rs | 2 - src/api/router/auth.rs | 2 +- 6 files changed, 89 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2d8a2d0f..590e4be4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -260,16 +260,43 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" dependencies = [ "async-trait", - "axum-core", + "axum-core 0.4.5", "bytes", "futures-util", "http", "http-body", "http-body-util", + "itoa", + "matchit 0.7.3", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "sync_wrapper", + "tower 0.5.2", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de45108900e1f9b9242f7f2e254aa3e2c029c921c258fe9e6b4217eeebd54288" +dependencies = [ + "axum-core 0.5.2", + "bytes", + "form_urlencoded", + "futures-util", + "http", + "http-body", + "http-body-util", "hyper", "hyper-util", "itoa", - "matchit", + "matchit 0.8.4", "memchr", "mime", "percent-encoding", @@ -289,11 +316,11 @@ dependencies = [ [[package]] name = "axum-client-ip" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9eefda7e2b27e1bda4d6fa8a06b50803b8793769045918bc37ad062d48a6efac" +checksum = "dff8ee1869817523c8f91c20bf17fd932707f66c2e7e0b0f811b29a227289562" dependencies = [ - "axum", + "axum 0.8.3", "forwarded-header-value", "serde", ] @@ -316,17 +343,36 @@ dependencies = [ "sync_wrapper", "tower-layer", "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68464cd0412f486726fb3373129ef5d2993f90c34bc2bc1c1e9943b2f4fc7ca6" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper", + "tower-layer", + "tower-service", "tracing", ] [[package]] name = "axum-extra" -version = "0.9.6" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c794b30c904f0a1c2fb7740f7df7f7972dfaa14ef6f57cb6178dc63e5dca2f04" +checksum = "45bf463831f5131b7d3c756525b305d40f1185b688565648a92e1392ca35713d" dependencies = [ - "axum", - "axum-core", + "axum 0.8.3", + "axum-core 0.5.2", "bytes", "futures-util", "headers", @@ -335,6 +381,7 @@ dependencies = [ "http-body-util", "mime", "pin-project-lite", + "rustversion", "serde", "tower 0.5.2", "tower-layer", @@ -778,7 +825,7 @@ name = "conduwuit_api" version = "0.5.0-rc.5" dependencies = [ "async-trait", - "axum", + "axum 0.8.3", "axum-client-ip", "axum-extra", "base64 0.22.1", @@ -811,7 +858,7 @@ version = "0.5.0-rc.5" dependencies = [ "argon2", "arrayvec", - "axum", + "axum 0.8.3", "axum-extra", "bytes", "bytesize", @@ -895,7 +942,7 @@ dependencies = [ name = "conduwuit_router" version = "0.5.0-rc.5" dependencies = [ - "axum", + "axum 0.8.3", "axum-client-ip", "axum-server", "axum-server-dual-protocol", @@ -2612,6 +2659,12 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" +[[package]] +name = "matchit" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" + [[package]] name = "maybe-rayon" version = "0.1.1" @@ -4884,7 +4937,7 @@ checksum = "877c5b330756d856ffcc4553ab34a5684481ade925ecc54bcd1bf02b1d0d4d52" dependencies = [ "async-stream", "async-trait", - "axum", + "axum 0.7.9", "base64 0.22.1", "bytes", "h2", diff --git a/Cargo.toml b/Cargo.toml index 1ce5c1db..e46c424c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -93,7 +93,7 @@ version = "1.3.1" version = "1.11.1" [workspace.dependencies.axum] -version = "0.7.9" +version = "0.8.3" default-features = false features = [ "form", @@ -106,7 +106,7 @@ features = [ ] [workspace.dependencies.axum-extra] -version = "0.9.6" +version = "0.10.1" default-features = false features = ["typed-header", "tracing"] @@ -119,7 +119,7 @@ default-features = false version = "0.7" [workspace.dependencies.axum-client-ip] -version = "0.6.1" +version = "0.7" [workspace.dependencies.tower] version = "0.5.2" diff --git a/src/api/client/unstable.rs b/src/api/client/unstable.rs index e21eaf21..1a700efa 100644 --- a/src/api/client/unstable.rs +++ b/src/api/client/unstable.rs @@ -60,7 +60,7 @@ pub(crate) async fn get_mutual_rooms_route( }) } -/// # `DELETE /_matrix/client/unstable/uk.tcpip.msc4133/profile/:user_id/us.cloke.msc4175.tz` +/// # `DELETE /_matrix/client/unstable/uk.tcpip.msc4133/profile/{user_id}/us.cloke.msc4175.tz` /// /// Deletes the `tz` (timezone) of a user, as per MSC4133 and MSC4175. /// @@ -88,7 +88,7 @@ pub(crate) async fn delete_timezone_key_route( Ok(delete_timezone_key::unstable::Response {}) } -/// # `PUT /_matrix/client/unstable/uk.tcpip.msc4133/profile/:user_id/us.cloke.msc4175.tz` +/// # `PUT /_matrix/client/unstable/uk.tcpip.msc4133/profile/{user_id}/us.cloke.msc4175.tz` /// /// Updates the `tz` (timezone) of a user, as per MSC4133 and MSC4175. /// @@ -268,7 +268,7 @@ pub(crate) async fn delete_profile_key_route( Ok(delete_profile_key::unstable::Response {}) } -/// # `GET /_matrix/client/unstable/uk.tcpip.msc4133/profile/:user_id/us.cloke.msc4175.tz` +/// # `GET /_matrix/client/unstable/uk.tcpip.msc4133/profile/{user_id}/us.cloke.msc4175.tz` /// /// Returns the `timezone` of the user as per MSC4133 and MSC4175. /// diff --git a/src/api/router.rs b/src/api/router.rs index 3fbef275..361a0ead 100644 --- a/src/api/router.rs +++ b/src/api/router.rs @@ -124,23 +124,23 @@ pub fn build(router: Router, server: &Server) -> Router { // Ruma doesn't have support for multiple paths for a single endpoint yet, and these routes // share one Ruma request / response type pair with {get,send}_state_event_for_key_route .route( - "/_matrix/client/r0/rooms/:room_id/state/:event_type", + "/_matrix/client/r0/rooms/{room_id}/state/{event_type}", get(client::get_state_events_for_empty_key_route) .put(client::send_state_event_for_empty_key_route), ) .route( - "/_matrix/client/v3/rooms/:room_id/state/:event_type", + "/_matrix/client/v3/rooms/{room_id}/state/{event_type}", get(client::get_state_events_for_empty_key_route) .put(client::send_state_event_for_empty_key_route), ) // These two endpoints allow trailing slashes .route( - "/_matrix/client/r0/rooms/:room_id/state/:event_type/", + "/_matrix/client/r0/rooms/{room_id}/state/{event_type}/", get(client::get_state_events_for_empty_key_route) .put(client::send_state_event_for_empty_key_route), ) .route( - "/_matrix/client/v3/rooms/:room_id/state/:event_type/", + "/_matrix/client/v3/rooms/{room_id}/state/{event_type}/", get(client::get_state_events_for_empty_key_route) .put(client::send_state_event_for_empty_key_route), ) @@ -180,7 +180,7 @@ pub fn build(router: Router, server: &Server) -> Router { .ruma_route(&client::get_mutual_rooms_route) .ruma_route(&client::get_room_summary) .route( - "/_matrix/client/unstable/im.nheko.summary/rooms/:room_id_or_alias/summary", + "/_matrix/client/unstable/im.nheko.summary/rooms/{room_id_or_alias}/summary", get(client::get_room_summary_legacy) ) .ruma_route(&client::well_known_support) @@ -194,7 +194,7 @@ pub fn build(router: Router, server: &Server) -> Router { .ruma_route(&server::get_server_version_route) .route("/_matrix/key/v2/server", get(server::get_server_keys_route)) .route( - "/_matrix/key/v2/server/:key_id", + "/_matrix/key/v2/server/{key_id}", get(server::get_server_keys_deprecated_route), ) .ruma_route(&server::get_public_rooms_route) @@ -228,9 +228,9 @@ pub fn build(router: Router, server: &Server) -> Router { .route("/_conduwuit/local_user_count", get(client::conduwuit_local_user_count)); } else { router = router - .route("/_matrix/federation/*path", any(federation_disabled)) + .route("/_matrix/federation/{*path}", any(federation_disabled)) .route("/.well-known/matrix/server", any(federation_disabled)) - .route("/_matrix/key/*path", any(federation_disabled)) + .route("/_matrix/key/{*path}", any(federation_disabled)) .route("/_conduwuit/local_user_count", any(federation_disabled)); } @@ -248,27 +248,27 @@ pub fn build(router: Router, server: &Server) -> Router { get(client::get_media_preview_legacy_legacy_route), ) .route( - "/_matrix/media/v1/download/:server_name/:media_id", + "/_matrix/media/v1/download/{server_name}/{media_id}", get(client::get_content_legacy_legacy_route), ) .route( - "/_matrix/media/v1/download/:server_name/:media_id/:file_name", + "/_matrix/media/v1/download/{server_name}/{media_id}/{file_name}", get(client::get_content_as_filename_legacy_legacy_route), ) .route( - "/_matrix/media/v1/thumbnail/:server_name/:media_id", + "/_matrix/media/v1/thumbnail/{server_name}/{media_id}", get(client::get_content_thumbnail_legacy_legacy_route), ); } else { router = router - .route("/_matrix/media/v1/*path", any(legacy_media_disabled)) + .route("/_matrix/media/v1/{*path}", any(legacy_media_disabled)) .route("/_matrix/media/v3/config", any(legacy_media_disabled)) - .route("/_matrix/media/v3/download/*path", any(legacy_media_disabled)) - .route("/_matrix/media/v3/thumbnail/*path", any(legacy_media_disabled)) + .route("/_matrix/media/v3/download/{*path}", any(legacy_media_disabled)) + .route("/_matrix/media/v3/thumbnail/{*path}", any(legacy_media_disabled)) .route("/_matrix/media/v3/preview_url", any(redirect_legacy_preview)) .route("/_matrix/media/r0/config", any(legacy_media_disabled)) - .route("/_matrix/media/r0/download/*path", any(legacy_media_disabled)) - .route("/_matrix/media/r0/thumbnail/*path", any(legacy_media_disabled)) + .route("/_matrix/media/r0/download/{*path}", any(legacy_media_disabled)) + .route("/_matrix/media/r0/thumbnail/{*path}", any(legacy_media_disabled)) .route("/_matrix/media/r0/preview_url", any(redirect_legacy_preview)); } diff --git a/src/api/router/args.rs b/src/api/router/args.rs index 26713dcc..5b3bac35 100644 --- a/src/api/router/args.rs +++ b/src/api/router/args.rs @@ -1,6 +1,5 @@ use std::{mem, ops::Deref}; -use async_trait::async_trait; use axum::{body::Body, extract::FromRequest}; use bytes::{BufMut, Bytes, BytesMut}; use conduwuit::{Error, Result, debug, debug_warn, err, trace, utils::string::EMPTY}; @@ -79,7 +78,6 @@ where fn deref(&self) -> &Self::Target { &self.body } } -#[async_trait] impl FromRequest for Args where T: IncomingRequest + Send + Sync + 'static, diff --git a/src/api/router/auth.rs b/src/api/router/auth.rs index 01254c32..3910f1ea 100644 --- a/src/api/router/auth.rs +++ b/src/api/router/auth.rs @@ -48,7 +48,7 @@ pub(super) async fn auth( json_body: Option<&CanonicalJsonValue>, metadata: &Metadata, ) -> Result { - let bearer: Option>> = request.parts.extract().await?; + let bearer: Option>> = request.parts.extract().await.unwrap_or(None); let token = match &bearer { | Some(TypedHeader(Authorization(bearer))) => Some(bearer.token()), | None => request.query.access_token.as_deref(), From 199d7320015edf8cb4d01ce4f6f1903cd1e03ab4 Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Mon, 28 Apr 2025 22:40:35 +0100 Subject: [PATCH 2/2] fixup! chore: Migrate to axum 0.8 --- Cargo.lock | 22 +++++++++++----------- Cargo.toml | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 590e4be4..9b2c69d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3705,7 +3705,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.10.1" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=62b675cc020624d11309797d6f02d75b9a1c448e#62b675cc020624d11309797d6f02d75b9a1c448e" dependencies = [ "assign", "js_int", @@ -3725,7 +3725,7 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.10.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=62b675cc020624d11309797d6f02d75b9a1c448e#62b675cc020624d11309797d6f02d75b9a1c448e" dependencies = [ "js_int", "ruma-common", @@ -3737,7 +3737,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.18.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=62b675cc020624d11309797d6f02d75b9a1c448e#62b675cc020624d11309797d6f02d75b9a1c448e" dependencies = [ "as_variant", "assign", @@ -3760,7 +3760,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.13.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=62b675cc020624d11309797d6f02d75b9a1c448e#62b675cc020624d11309797d6f02d75b9a1c448e" dependencies = [ "as_variant", "base64 0.22.1", @@ -3792,7 +3792,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.28.1" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=62b675cc020624d11309797d6f02d75b9a1c448e#62b675cc020624d11309797d6f02d75b9a1c448e" dependencies = [ "as_variant", "indexmap 2.8.0", @@ -3817,7 +3817,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=62b675cc020624d11309797d6f02d75b9a1c448e#62b675cc020624d11309797d6f02d75b9a1c448e" dependencies = [ "bytes", "headers", @@ -3839,7 +3839,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.9.5" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=62b675cc020624d11309797d6f02d75b9a1c448e#62b675cc020624d11309797d6f02d75b9a1c448e" dependencies = [ "js_int", "thiserror 2.0.12", @@ -3848,7 +3848,7 @@ dependencies = [ [[package]] name = "ruma-identity-service-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=62b675cc020624d11309797d6f02d75b9a1c448e#62b675cc020624d11309797d6f02d75b9a1c448e" dependencies = [ "js_int", "ruma-common", @@ -3858,7 +3858,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.13.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=62b675cc020624d11309797d6f02d75b9a1c448e#62b675cc020624d11309797d6f02d75b9a1c448e" dependencies = [ "cfg-if", "proc-macro-crate", @@ -3873,7 +3873,7 @@ dependencies = [ [[package]] name = "ruma-push-gateway-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=62b675cc020624d11309797d6f02d75b9a1c448e#62b675cc020624d11309797d6f02d75b9a1c448e" dependencies = [ "js_int", "ruma-common", @@ -3885,7 +3885,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.15.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d6870a7fb7f6cccff63f7fd0ff6c581bad80e983#d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=62b675cc020624d11309797d6f02d75b9a1c448e#62b675cc020624d11309797d6f02d75b9a1c448e" dependencies = [ "base64 0.22.1", "ed25519-dalek", diff --git a/Cargo.toml b/Cargo.toml index e46c424c..78125ee0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -350,7 +350,7 @@ version = "0.1.2" [workspace.dependencies.ruma] git = "https://forgejo.ellis.link/continuwuation/ruwuma" #branch = "conduwuit-changes" -rev = "d6870a7fb7f6cccff63f7fd0ff6c581bad80e983" +rev = "62b675cc020624d11309797d6f02d75b9a1c448e" features = [ "compat", "rand",