mirror of
https://github.com/tokio-rs/axum.git
synced 2025-03-13 19:27:53 +01: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
2 changed files with 23 additions and 5 deletions
|
@ -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))
|
||||
- Implement `FromRequest` for `http::Extensions`
|
||||
- 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
|
||||
|
||||
|
|
|
@ -374,7 +374,12 @@ pub struct RequestParts<B = crate::body::Body> {
|
|||
}
|
||||
|
||||
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 (
|
||||
http::request::Parts {
|
||||
method,
|
||||
|
@ -397,9 +402,21 @@ impl<B> RequestParts<B> {
|
|||
}
|
||||
}
|
||||
|
||||
// this method uses `Error` since we might make this method public one day and then
|
||||
// `Error` is more flexible.
|
||||
pub(crate) fn try_into_request(self) -> Result<Request<B>, Error> {
|
||||
/// Convert this `RequestParts` back into a [`Request`].
|
||||
///
|
||||
/// 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 {
|
||||
method,
|
||||
uri,
|
||||
|
|
Loading…
Add table
Reference in a new issue