Feature flag for axum-original-uri
This commit is contained in:
parent
ae7910e5f5
commit
4c373c5dc8
2 changed files with 17 additions and 9 deletions
|
|
@ -12,6 +12,7 @@ documentation = "https://docs.rs/activitypub_federation/"
|
||||||
default = ["actix-web", "axum"]
|
default = ["actix-web", "axum"]
|
||||||
actix-web = ["dep:actix-web", "dep:http02"]
|
actix-web = ["dep:actix-web", "dep:http02"]
|
||||||
axum = ["dep:axum", "dep:tower"]
|
axum = ["dep:axum", "dep:tower"]
|
||||||
|
axum-original-uri = ["dep:axum", "axum/original-uri"]
|
||||||
|
|
||||||
[lints.rust]
|
[lints.rust]
|
||||||
warnings = "deny"
|
warnings = "deny"
|
||||||
|
|
@ -84,8 +85,7 @@ http02 = { package = "http", version = "0.2.12", optional = true }
|
||||||
|
|
||||||
# Axum
|
# Axum
|
||||||
axum = { version = "0.8.4", features = [
|
axum = { version = "0.8.4", features = [
|
||||||
"json",
|
"json"
|
||||||
"original-uri",
|
|
||||||
], default-features = false, optional = true }
|
], default-features = false, optional = true }
|
||||||
tower = { version = "0.5.2", optional = true }
|
tower = { version = "0.5.2", optional = true }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,11 @@ use crate::{
|
||||||
};
|
};
|
||||||
use axum::{
|
use axum::{
|
||||||
body::Body,
|
body::Body,
|
||||||
extract::{FromRequest, FromRequestParts, OriginalUri},
|
extract::FromRequest,
|
||||||
http::{Request, StatusCode},
|
http::{Request, StatusCode},
|
||||||
response::{IntoResponse, Response},
|
response::{IntoResponse, Response},
|
||||||
};
|
};
|
||||||
use http::{HeaderMap, Method};
|
use http::{HeaderMap, Method, Uri};
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
|
|
@ -53,7 +53,7 @@ where
|
||||||
pub struct ActivityData {
|
pub struct ActivityData {
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
method: Method,
|
method: Method,
|
||||||
uri: OriginalUri,
|
uri: Uri,
|
||||||
body: Vec<u8>,
|
body: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,14 +63,22 @@ where
|
||||||
{
|
{
|
||||||
type Rejection = Response;
|
type Rejection = Response;
|
||||||
|
|
||||||
async fn from_request(req: Request<Body>, state: &S) -> Result<Self, Self::Rejection> {
|
async fn from_request(req: Request<Body>, _state: &S) -> Result<Self, Self::Rejection> {
|
||||||
|
#[allow(unused_mut)]
|
||||||
let (mut parts, body) = req.into_parts();
|
let (mut parts, body) = req.into_parts();
|
||||||
|
|
||||||
// take the full URI to handle nested routers
|
// take the full URI to handle nested routers
|
||||||
// OriginalUri::from_request_parts has an Infallible error type
|
// OriginalUri::from_request_parts has an Infallible error type
|
||||||
let uri = OriginalUri::from_request_parts(&mut parts, state)
|
#[cfg(feature = "axum-original-uri")]
|
||||||
.await
|
let uri = {
|
||||||
.expect("infallible");
|
use axum::extract::{FromRequestParts, OriginalUri};
|
||||||
|
OriginalUri::from_request_parts(&mut parts, _state)
|
||||||
|
.await
|
||||||
|
.expect("infallible")
|
||||||
|
.0
|
||||||
|
};
|
||||||
|
#[cfg(not(feature = "axum-original-uri"))]
|
||||||
|
let uri = parts.uri;
|
||||||
|
|
||||||
// this wont work if the body is an long running stream
|
// this wont work if the body is an long running stream
|
||||||
let bytes = axum::body::to_bytes(body, usize::MAX)
|
let bytes = axum::body::to_bytes(body, usize::MAX)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue