Remove RequestParts::take_extensions (#699)

* Remove `RequestParts::take_extensions`

* fix out of date docs

* Remove RequestAlreadyExtracted and replace it with BodyAlreadyExtracted

* fix docs

* fix test

* Update axum-core/src/extract/mod.rs

Co-authored-by: Jonas Platte <[email protected]>

* Remove macro only used once

Co-authored-by: Jonas Platte <[email protected]>
This commit is contained in:
David Pedersen
2022-01-23 18:01:52 +01:00
co-authored by Jonas Platte
parent 184ea656c0
commit b1ef0be1a7
14 changed files with 98 additions and 228 deletions
+27 -33
View File
@@ -1,21 +1,36 @@
//! Rejection response types.
define_rejection! {
#[status = INTERNAL_SERVER_ERROR]
#[body = "Cannot have two request body extractors for a single handler"]
/// Rejection type used if you try and extract the request body more than
/// once.
pub struct BodyAlreadyExtracted;
use crate::body;
use http::{Response, StatusCode};
use http_body::Full;
use std::fmt;
/// Rejection type used if you try and extract the request body more than
/// once.
#[derive(Debug, Default)]
#[non_exhaustive]
pub struct BodyAlreadyExtracted;
impl BodyAlreadyExtracted {
const BODY: &'static str = "Cannot have two request body extractors for a single handler";
}
define_rejection! {
#[status = INTERNAL_SERVER_ERROR]
#[body = "Extensions taken by other extractor"]
/// Rejection used if the request extension has been taken by another
/// extractor.
pub struct ExtensionsAlreadyExtracted;
impl crate::response::IntoResponse for BodyAlreadyExtracted {
fn into_response(self) -> crate::response::Response {
let mut res = Response::new(body::boxed(Full::from(Self::BODY)));
*res.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
res
}
}
impl fmt::Display for BodyAlreadyExtracted {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", Self::BODY)
}
}
impl std::error::Error for BodyAlreadyExtracted {}
define_rejection! {
#[status = BAD_REQUEST]
#[body = "Failed to buffer the request body"]
@@ -32,18 +47,6 @@ define_rejection! {
pub struct InvalidUtf8(Error);
}
composite_rejection! {
/// Rejection used for [`Request<_>`].
///
/// Contains one variant for each way the [`Request<_>`] extractor can fail.
///
/// [`Request<_>`]: http::Request
pub enum RequestAlreadyExtracted {
BodyAlreadyExtracted,
ExtensionsAlreadyExtracted,
}
}
composite_rejection! {
/// Rejection used for [`Bytes`](bytes::Bytes).
///
@@ -65,12 +68,3 @@ composite_rejection! {
InvalidUtf8,
}
}
composite_rejection! {
/// Rejection used for [`http::request::Parts`].
///
/// Contains one variant for each way the [`http::request::Parts`] extractor can fail.
pub enum RequestPartsAlreadyExtracted {
ExtensionsAlreadyExtracted,
}
}