Use extensions directly in from_request_parts (#3542)

This commit is contained in:
Brad Dunbar
2025-10-30 08:40:00 -04:00
committed by GitHub
parent c4890b844b
commit efc1f57b15
+3 -5
View File
@@ -1,4 +1,4 @@
use axum::extract::{Extension, FromRequestParts};
use axum::extract::FromRequestParts;
use http::request::Parts;
/// Cache results of other extractors.
@@ -88,10 +88,8 @@ where
type Rejection = T::Rejection;
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
if let Ok(Extension(CachedEntry(value))) =
Extension::<CachedEntry<T>>::from_request_parts(parts, state).await
{
Ok(Self(value))
if let Some(value) = parts.extensions.get::<CachedEntry<T>>() {
Ok(Self(value.0.clone()))
} else {
let value = T::from_request_parts(parts, state).await?;
parts.extensions.insert(CachedEntry(value.clone()));