diff --git a/CHANGELOG.md b/CHANGELOG.md index b8e6981e..c829056d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/extract/mod.rs b/src/extract/mod.rs index bec4954a..0308f183 100644 --- a/src/extract/mod.rs +++ b/src/extract/mod.rs @@ -374,7 +374,12 @@ pub struct RequestParts { } impl RequestParts { - pub(crate) fn new(req: Request) -> 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) -> Self { let ( http::request::Parts { method, @@ -397,9 +402,21 @@ impl RequestParts { } } - // 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, 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, Error> { let Self { method, uri,