mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-28 00:00:20 +02:00
Implement FromRequest for http::Extensions (#169)
Not sure its very useful but odd to not provide this. All other request parts have an extractor and we already have the rejection for it.
This commit is contained in:
@@ -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<B> FromRequest<B> for Extensions
|
||||
where
|
||||
B: Send,
|
||||
{
|
||||
type Rejection = ExtensionsAlreadyExtracted;
|
||||
|
||||
async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
|
||||
req.take_extensions().ok_or(ExtensionsAlreadyExtracted)
|
||||
}
|
||||
}
|
||||
|
||||
/// Extractor that extracts the request body as a [`Stream`].
|
||||
///
|
||||
/// # Example
|
||||
|
||||
Reference in New Issue
Block a user