mirror of
https://github.com/tokio-rs/axum.git
synced 2025-09-30 22:41:03 +00:00
Make RequestParts::{new, try_into_request}
public (#194)
Fixes https://github.com/tokio-rs/axum/issues/147
This commit is contained in:
parent
b4cbd7f147
commit
baa99e5084
@ -14,7 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Add `NestedUri` for extracting request URI in nested services ([#161](https://github.com/tokio-rs/axum/pull/161))
|
- Add `NestedUri` for extracting request URI in nested services ([#161](https://github.com/tokio-rs/axum/pull/161))
|
||||||
- Implement `FromRequest` for `http::Extensions`
|
- Implement `FromRequest` for `http::Extensions`
|
||||||
- Implement SSE as an `IntoResponse` instead of a service ([#98](https://github.com/tokio-rs/axum/pull/98))
|
- Implement SSE as an `IntoResponse` instead of a service ([#98](https://github.com/tokio-rs/axum/pull/98))
|
||||||
- Add `Redirect` response.
|
- Add `Redirect` response. ([#192](https://github.com/tokio-rs/axum/pull/192))
|
||||||
|
- Make `RequestParts::{new, try_into_request}` public ([#194](https://github.com/tokio-rs/axum/pull/194))
|
||||||
|
|
||||||
## Breaking changes
|
## Breaking changes
|
||||||
|
|
||||||
|
@ -374,7 +374,12 @@ pub struct RequestParts<B = crate::body::Body> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<B> RequestParts<B> {
|
impl<B> RequestParts<B> {
|
||||||
pub(crate) fn new(req: Request<B>) -> Self {
|
/// Create a new `RequestParts`.
|
||||||
|
///
|
||||||
|
/// You generally shouldn't need to construct this type yourself, unless
|
||||||
|
/// using extractors outside of axum for example to implement a
|
||||||
|
/// [`tower::Service`].
|
||||||
|
pub fn new(req: Request<B>) -> Self {
|
||||||
let (
|
let (
|
||||||
http::request::Parts {
|
http::request::Parts {
|
||||||
method,
|
method,
|
||||||
@ -397,9 +402,21 @@ impl<B> RequestParts<B> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this method uses `Error` since we might make this method public one day and then
|
/// Convert this `RequestParts` back into a [`Request`].
|
||||||
// `Error` is more flexible.
|
///
|
||||||
pub(crate) fn try_into_request(self) -> Result<Request<B>, Error> {
|
/// Fails if
|
||||||
|
///
|
||||||
|
/// - The full [`HeaderMap`] has been extracted, that is [`take_headers`]
|
||||||
|
/// have been called.
|
||||||
|
/// - The full [`Extensions`] has been extracted, that is
|
||||||
|
/// [`take_extensions`] have been called.
|
||||||
|
/// - The request body has been extracted, that is [`take_body`] have been
|
||||||
|
/// called.
|
||||||
|
///
|
||||||
|
/// [`take_headers`]: RequestParts::take_headers
|
||||||
|
/// [`take_extensions`]: RequestParts::take_extensions
|
||||||
|
/// [`take_body`]: RequestParts::take_body
|
||||||
|
pub fn try_into_request(self) -> Result<Request<B>, Error> {
|
||||||
let Self {
|
let Self {
|
||||||
method,
|
method,
|
||||||
uri,
|
uri,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user