mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-03 00:00:07 +02:00
Implement FromRequestParts for Parts and Extensions (#2328)
This commit is contained in:
@@ -2,7 +2,7 @@ use super::{rejection::*, FromRequest, FromRequestParts, Request};
|
|||||||
use crate::{body::Body, RequestExt};
|
use crate::{body::Body, RequestExt};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use http::{request::Parts, HeaderMap, Method, Uri, Version};
|
use http::{request::Parts, Extensions, HeaderMap, Method, Uri, Version};
|
||||||
use http_body_util::BodyExt;
|
use http_body_util::BodyExt;
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
|
|
||||||
@@ -115,14 +115,26 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<S> FromRequest<S> for Parts
|
impl<S> FromRequestParts<S> for Parts
|
||||||
where
|
where
|
||||||
S: Send + Sync,
|
S: Send + Sync,
|
||||||
{
|
{
|
||||||
type Rejection = Infallible;
|
type Rejection = Infallible;
|
||||||
|
|
||||||
async fn from_request(req: Request, _: &S) -> Result<Self, Self::Rejection> {
|
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
|
||||||
Ok(req.into_parts().0)
|
Ok(parts.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl<S> FromRequestParts<S> for Extensions
|
||||||
|
where
|
||||||
|
S: Send + Sync,
|
||||||
|
{
|
||||||
|
type Rejection = Infallible;
|
||||||
|
|
||||||
|
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
|
||||||
|
Ok(parts.extensions.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ error[E0277]: the trait bound `bool: FromRequestParts<()>` is not satisfied
|
|||||||
<HeaderMap as FromRequestParts<S>>
|
<HeaderMap as FromRequestParts<S>>
|
||||||
<Extension<T> as FromRequestParts<S>>
|
<Extension<T> as FromRequestParts<S>>
|
||||||
<Method as FromRequestParts<S>>
|
<Method as FromRequestParts<S>>
|
||||||
|
<axum::http::request::Parts as FromRequestParts<S>>
|
||||||
<Uri as FromRequestParts<S>>
|
<Uri as FromRequestParts<S>>
|
||||||
<ConnectInfo<T> as FromRequestParts<S>>
|
<ConnectInfo<T> as FromRequestParts<S>>
|
||||||
<Version as FromRequestParts<S>>
|
<Version as FromRequestParts<S>>
|
||||||
<axum::extract::Path<T> as FromRequestParts<S>>
|
<Extensions as FromRequestParts<S>>
|
||||||
<RawPathParams as FromRequestParts<S>>
|
|
||||||
and $N others
|
and $N others
|
||||||
= note: required for `bool` to implement `FromRequest<(), axum_core::extract::private::ViaParts>`
|
= note: required for `bool` to implement `FromRequest<(), axum_core::extract::private::ViaParts>`
|
||||||
note: required by a bound in `__axum_macros_check_handler_0_from_request_check`
|
note: required by a bound in `__axum_macros_check_handler_0_from_request_check`
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ error[E0277]: the trait bound `String: FromRequestParts<S>` is not satisfied
|
|||||||
<HeaderMap as FromRequestParts<S>>
|
<HeaderMap as FromRequestParts<S>>
|
||||||
<Extension<T> as FromRequestParts<S>>
|
<Extension<T> as FromRequestParts<S>>
|
||||||
<Method as FromRequestParts<S>>
|
<Method as FromRequestParts<S>>
|
||||||
|
<axum::http::request::Parts as FromRequestParts<S>>
|
||||||
<Uri as FromRequestParts<S>>
|
<Uri as FromRequestParts<S>>
|
||||||
<ConnectInfo<T> as FromRequestParts<S>>
|
<ConnectInfo<T> as FromRequestParts<S>>
|
||||||
<Version as FromRequestParts<S>>
|
<Version as FromRequestParts<S>>
|
||||||
<axum::extract::Path<T> as FromRequestParts<S>>
|
|
||||||
and $N others
|
and $N others
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- **breaking:** `impl<T> IntoResponse(Parts) for Extension<T>` now requires
|
- **breaking:** `impl<T> IntoResponse(Parts) for Extension<T>` now requires
|
||||||
`T: Clone`, as that is required by the http crate ([#1882])
|
`T: Clone`, as that is required by the http crate ([#1882])
|
||||||
- **added:** Add `axum::Json::from_bytes` ([#2244])
|
- **added:** Add `axum::Json::from_bytes` ([#2244])
|
||||||
|
- **added:** Implement `FromRequestParts` for `http::request::Parts` ([#2328])
|
||||||
|
- **added:** Implement `FromRequestParts` for `http::Extensions` ([#2328])
|
||||||
|
|
||||||
[#1664]: https://github.com/tokio-rs/axum/pull/1664
|
[#1664]: https://github.com/tokio-rs/axum/pull/1664
|
||||||
[#1751]: https://github.com/tokio-rs/axum/pull/1751
|
[#1751]: https://github.com/tokio-rs/axum/pull/1751
|
||||||
@@ -91,6 +93,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
[#2143]: https://github.com/tokio-rs/axum/pull/2143
|
[#2143]: https://github.com/tokio-rs/axum/pull/2143
|
||||||
[#2149]: https://github.com/tokio-rs/axum/pull/2149
|
[#2149]: https://github.com/tokio-rs/axum/pull/2149
|
||||||
[#2244]: https://github.com/tokio-rs/axum/pull/2244
|
[#2244]: https://github.com/tokio-rs/axum/pull/2244
|
||||||
|
[#2328]: https://github.com/tokio-rs/axum/pull/2328
|
||||||
|
|
||||||
# 0.6.17 (25. April, 2023)
|
# 0.6.17 (25. April, 2023)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user