mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-07 00:00:12 +02:00
Use extensions directly in from_request_parts (#3542)
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use axum::extract::{Extension, FromRequestParts};
|
use axum::extract::FromRequestParts;
|
||||||
use http::request::Parts;
|
use http::request::Parts;
|
||||||
|
|
||||||
/// Cache results of other extractors.
|
/// Cache results of other extractors.
|
||||||
@@ -88,13 +88,12 @@ where
|
|||||||
type Rejection = T::Rejection;
|
type Rejection = T::Rejection;
|
||||||
|
|
||||||
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
|
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
|
||||||
match Extension::<CachedEntry<T>>::from_request_parts(parts, state).await {
|
if let Some(value) = parts.extensions.get::<CachedEntry<T>>() {
|
||||||
Ok(Extension(CachedEntry(value))) => Ok(Self(value)),
|
Ok(Self(value.0.clone()))
|
||||||
Err(_) => {
|
} else {
|
||||||
let value = T::from_request_parts(parts, state).await?;
|
let value = T::from_request_parts(parts, state).await?;
|
||||||
parts.extensions.insert(CachedEntry(value.clone()));
|
parts.extensions.insert(CachedEntry(value.clone()));
|
||||||
Ok(Self(value))
|
Ok(Self(value))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user