diff --git a/Cargo.toml b/Cargo.toml index 9efc56b..20453fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -88,7 +88,7 @@ actix-web = { version = "4.8.0", default-features = false, optional = true } http02 = { package = "http", version = "0.2.12", optional = true } # Axum -axum = { version = "0.7.5", features = ["json"], default-features = false, optional = true } +axum = { version = "0.7.5", features = ["json", "original-uri"], default-features = false, optional = true } tower = { version = "0.4.13", optional = true } [dev-dependencies] diff --git a/src/axum/inbox.rs b/src/axum/inbox.rs index 1767c10..9dfe27d 100644 --- a/src/axum/inbox.rs +++ b/src/axum/inbox.rs @@ -12,11 +12,11 @@ use crate::{ use axum::{ async_trait, body::Body, - extract::FromRequest, + extract::{FromRequest, FromRequestParts, OriginalUri}, http::{Request, StatusCode}, response::{IntoResponse, Response}, }; -use http::{HeaderMap, Method, Uri}; +use http::{HeaderMap, Method}; use serde::de::DeserializeOwned; use tracing::debug; @@ -54,7 +54,7 @@ where pub struct ActivityData { headers: HeaderMap, method: Method, - uri: Uri, + uri: OriginalUri, body: Vec, } @@ -65,8 +65,12 @@ where { type Rejection = Response; - async fn from_request(req: Request, _state: &S) -> Result { - let (parts, body) = req.into_parts(); + async fn from_request(req: Request, state: &S) -> Result { + let (mut parts, body) = req.into_parts(); + + // take the full URI to handle nested routers + // OriginalUri::from_request_parts has an Infallible error type + let Ok(uri) = OriginalUri::from_request_parts(&mut parts, state).await; // this wont work if the body is an long running stream let bytes = axum::body::to_bytes(body, usize::MAX) @@ -76,7 +80,7 @@ where Ok(Self { headers: parts.headers, method: parts.method, - uri: parts.uri, + uri, body: bytes.to_vec(), }) }