From 9a975c0304d11509501a28fb48a97f6d3f2c346c Mon Sep 17 00:00:00 2001 From: Jade Ellis Date: Mon, 28 Apr 2025 22:39:32 +0100 Subject: [PATCH] chore: Migrate to axum 0.8 Co-authored-by: dasha_uwu Co-authored-by: Jason Volk Signed-off-by: Jason Volk --- Cargo.lock | 48 +++++++++++++++++++------------------- Cargo.toml | 9 +++---- src/api/client/unstable.rs | 6 ++--- src/api/router.rs | 32 ++++++++++++------------- src/api/router/args.rs | 2 -- src/api/router/auth.rs | 3 ++- 6 files changed, 50 insertions(+), 50 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 017a967d..d40484af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -261,13 +261,13 @@ dependencies = [ [[package]] name = "axum" -version = "0.7.9" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" +checksum = "021e862c184ae977658b36c4500f7feac3221ca5da43e3f25bd04ab6c79a29b5" dependencies = [ - "async-trait", "axum-core", "bytes", + "form_urlencoded", "futures-util", "http", "http-body", @@ -295,9 +295,9 @@ 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", "forwarded-header-value", @@ -306,13 +306,12 @@ dependencies = [ [[package]] name = "axum-core" -version = "0.4.5" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199" +checksum = "68464cd0412f486726fb3373129ef5d2993f90c34bc2bc1c1e9943b2f4fc7ca6" dependencies = [ - "async-trait", "bytes", - "futures-util", + "futures-core", "http", "http-body", "http-body-util", @@ -327,9 +326,9 @@ dependencies = [ [[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", @@ -341,6 +340,7 @@ dependencies = [ "http-body-util", "mime", "pin-project-lite", + "rustversion", "serde", "tower", "tower-layer", @@ -2409,9 +2409,9 @@ dependencies = [ [[package]] name = "matchit" -version = "0.7.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" +checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" [[package]] name = "maybe-rayon" @@ -3438,7 +3438,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.10.1" -source = "git+https://github.com/matrix-construct/ruma?rev=920148dca1076454ca0ca5d43b5ce1aa708381d4#920148dca1076454ca0ca5d43b5ce1aa708381d4" +source = "git+https://github.com/matrix-construct/ruma?rev=a91c1b70fa3cc57fc87a6ce92d2c42a19124a666#a91c1b70fa3cc57fc87a6ce92d2c42a19124a666" dependencies = [ "assign", "js_int", @@ -3458,7 +3458,7 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.10.0" -source = "git+https://github.com/matrix-construct/ruma?rev=920148dca1076454ca0ca5d43b5ce1aa708381d4#920148dca1076454ca0ca5d43b5ce1aa708381d4" +source = "git+https://github.com/matrix-construct/ruma?rev=a91c1b70fa3cc57fc87a6ce92d2c42a19124a666#a91c1b70fa3cc57fc87a6ce92d2c42a19124a666" dependencies = [ "js_int", "ruma-common", @@ -3470,7 +3470,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.18.0" -source = "git+https://github.com/matrix-construct/ruma?rev=920148dca1076454ca0ca5d43b5ce1aa708381d4#920148dca1076454ca0ca5d43b5ce1aa708381d4" +source = "git+https://github.com/matrix-construct/ruma?rev=a91c1b70fa3cc57fc87a6ce92d2c42a19124a666#a91c1b70fa3cc57fc87a6ce92d2c42a19124a666" dependencies = [ "as_variant", "assign", @@ -3493,7 +3493,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.13.0" -source = "git+https://github.com/matrix-construct/ruma?rev=920148dca1076454ca0ca5d43b5ce1aa708381d4#920148dca1076454ca0ca5d43b5ce1aa708381d4" +source = "git+https://github.com/matrix-construct/ruma?rev=a91c1b70fa3cc57fc87a6ce92d2c42a19124a666#a91c1b70fa3cc57fc87a6ce92d2c42a19124a666" dependencies = [ "as_variant", "base64", @@ -3525,7 +3525,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.28.1" -source = "git+https://github.com/matrix-construct/ruma?rev=920148dca1076454ca0ca5d43b5ce1aa708381d4#920148dca1076454ca0ca5d43b5ce1aa708381d4" +source = "git+https://github.com/matrix-construct/ruma?rev=a91c1b70fa3cc57fc87a6ce92d2c42a19124a666#a91c1b70fa3cc57fc87a6ce92d2c42a19124a666" dependencies = [ "as_variant", "indexmap", @@ -3550,7 +3550,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.9.0" -source = "git+https://github.com/matrix-construct/ruma?rev=920148dca1076454ca0ca5d43b5ce1aa708381d4#920148dca1076454ca0ca5d43b5ce1aa708381d4" +source = "git+https://github.com/matrix-construct/ruma?rev=a91c1b70fa3cc57fc87a6ce92d2c42a19124a666#a91c1b70fa3cc57fc87a6ce92d2c42a19124a666" dependencies = [ "bytes", "headers", @@ -3572,7 +3572,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.9.5" -source = "git+https://github.com/matrix-construct/ruma?rev=920148dca1076454ca0ca5d43b5ce1aa708381d4#920148dca1076454ca0ca5d43b5ce1aa708381d4" +source = "git+https://github.com/matrix-construct/ruma?rev=a91c1b70fa3cc57fc87a6ce92d2c42a19124a666#a91c1b70fa3cc57fc87a6ce92d2c42a19124a666" dependencies = [ "js_int", "thiserror 2.0.12", @@ -3581,7 +3581,7 @@ dependencies = [ [[package]] name = "ruma-identity-service-api" version = "0.9.0" -source = "git+https://github.com/matrix-construct/ruma?rev=920148dca1076454ca0ca5d43b5ce1aa708381d4#920148dca1076454ca0ca5d43b5ce1aa708381d4" +source = "git+https://github.com/matrix-construct/ruma?rev=a91c1b70fa3cc57fc87a6ce92d2c42a19124a666#a91c1b70fa3cc57fc87a6ce92d2c42a19124a666" dependencies = [ "js_int", "ruma-common", @@ -3591,7 +3591,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.13.0" -source = "git+https://github.com/matrix-construct/ruma?rev=920148dca1076454ca0ca5d43b5ce1aa708381d4#920148dca1076454ca0ca5d43b5ce1aa708381d4" +source = "git+https://github.com/matrix-construct/ruma?rev=a91c1b70fa3cc57fc87a6ce92d2c42a19124a666#a91c1b70fa3cc57fc87a6ce92d2c42a19124a666" dependencies = [ "cfg-if", "proc-macro-crate", @@ -3606,7 +3606,7 @@ dependencies = [ [[package]] name = "ruma-push-gateway-api" version = "0.9.0" -source = "git+https://github.com/matrix-construct/ruma?rev=920148dca1076454ca0ca5d43b5ce1aa708381d4#920148dca1076454ca0ca5d43b5ce1aa708381d4" +source = "git+https://github.com/matrix-construct/ruma?rev=a91c1b70fa3cc57fc87a6ce92d2c42a19124a666#a91c1b70fa3cc57fc87a6ce92d2c42a19124a666" dependencies = [ "js_int", "ruma-common", @@ -3618,7 +3618,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.15.0" -source = "git+https://github.com/matrix-construct/ruma?rev=920148dca1076454ca0ca5d43b5ce1aa708381d4#920148dca1076454ca0ca5d43b5ce1aa708381d4" +source = "git+https://github.com/matrix-construct/ruma?rev=a91c1b70fa3cc57fc87a6ce92d2c42a19124a666#a91c1b70fa3cc57fc87a6ce92d2c42a19124a666" dependencies = [ "base64", "ed25519-dalek", diff --git a/Cargo.toml b/Cargo.toml index 32457559..3489c831 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,7 @@ version = "2.3.1" version = "0.1.88" [workspace.dependencies.axum] -version = "0.7.9" +version = "0.8.3" default-features = false features = [ "form", @@ -70,10 +70,10 @@ features = [ ] [workspace.dependencies.axum-client-ip] -version = "0.6.1" +version = "0.7" [workspace.dependencies.axum-extra] -version = "0.9.6" +version = "0.10.1" default-features = false features = [ "typed-header", @@ -86,6 +86,7 @@ default-features = false [workspace.dependencies.axum-server-dual-protocol] version = "0.7" +default-features = false [workspace.dependencies.base64] version = "0.22.1" @@ -304,7 +305,7 @@ default-features = false [workspace.dependencies.ruma] git = "https://github.com/matrix-construct/ruma" -rev = "920148dca1076454ca0ca5d43b5ce1aa708381d4" +rev = "a91c1b70fa3cc57fc87a6ce92d2c42a19124a666" features = [ "compat", "rand", diff --git a/src/api/client/unstable.rs b/src/api/client/unstable.rs index 12cc1918..cff2e96f 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. /// @@ -270,7 +270,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 041ab933..91550832 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), ) @@ -179,7 +179,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) @@ -193,7 +193,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) @@ -227,9 +227,9 @@ pub fn build(router: Router, server: &Server) -> Router { .route("/_tuwunel/local_user_count", get(client::tuwunel_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("/_tuwunel/local_user_count", any(federation_disabled)); } @@ -247,27 +247,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 87c49bea..6e4edbe9 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 ruma::{ @@ -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 b2c73678..b999cce4 100644 --- a/src/api/router/auth.rs +++ b/src/api/router/auth.rs @@ -48,7 +48,8 @@ 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(),