diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c7daddd..e85f4d60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `RoutingDsl::or` for combining routes ([#108](https://github.com/tokio-rs/axum/pull/108)) - Add `handle_error` to `service::OnMethod` ([#160](https://github.com/tokio-rs/axum/pull/160)) - Add `NestedUri` for extracting request URI in nested services ([#161](https://github.com/tokio-rs/axum/pull/161)) +- Implement `FromRequest` for `http::Extensions` ## Breaking changes diff --git a/src/extract/request_parts.rs b/src/extract/request_parts.rs index 55c72029..c2a3e7bd 100644 --- a/src/extract/request_parts.rs +++ b/src/extract/request_parts.rs @@ -2,7 +2,7 @@ use super::{rejection::*, take_body, Extension, FromRequest, RequestParts}; use async_trait::async_trait; use bytes::Bytes; use futures_util::stream::Stream; -use http::{HeaderMap, Method, Request, Uri, Version}; +use http::{Extensions, HeaderMap, Method, Request, Uri, Version}; use std::{ convert::Infallible, pin::Pin, @@ -148,6 +148,18 @@ where } } +#[async_trait] +impl FromRequest for Extensions +where + B: Send, +{ + type Rejection = ExtensionsAlreadyExtracted; + + async fn from_request(req: &mut RequestParts) -> Result { + req.take_extensions().ok_or(ExtensionsAlreadyExtracted) + } +} + /// Extractor that extracts the request body as a [`Stream`]. /// /// # Example