Remove B type param (#1751)

Co-authored-by: Jonas Platte <[email protected]>
Co-authored-by: Michael Scofield <[email protected]>
This commit is contained in:
David Pedersen
2023-04-21 17:45:31 +02:00
co-authored by Jonas Platte Michael Scofield
parent 9be0ea934c
commit 4e4c29175f
100 changed files with 966 additions and 1160 deletions
+2 -2
View File
@@ -255,7 +255,7 @@ mod tests {
custom_key: CustomKey(Key::generate()),
};
let app = Router::<_, Body>::new()
let app = Router::new()
.route("/set", get(set_cookie))
.route("/get", get(get_cookie))
.route("/remove", get(remove_cookie))
@@ -352,7 +352,7 @@ mod tests {
custom_key: CustomKey(Key::generate()),
};
let app = Router::<_, Body>::new()
let app = Router::new()
.route("/get", get(get_cookie))
.with_state(state);
+4 -7
View File
@@ -1,9 +1,9 @@
use axum::{
async_trait,
body::HttpBody,
body::Body,
extract::{rejection::RawFormRejection, FromRequest, RawForm},
response::{IntoResponse, Response},
BoxError, Error, RequestExt,
Error, RequestExt,
};
use http::{Request, StatusCode};
use serde::de::DeserializeOwned;
@@ -46,17 +46,14 @@ pub struct Form<T>(pub T);
axum_core::__impl_deref!(Form);
#[async_trait]
impl<T, S, B> FromRequest<S, B> for Form<T>
impl<T, S> FromRequest<S> for Form<T>
where
T: DeserializeOwned,
B: HttpBody + Send + 'static,
B::Data: Send,
B::Error: Into<BoxError>,
S: Send + Sync,
{
type Rejection = FormRejection;
async fn from_request(req: Request<B>, _state: &S) -> Result<Self, Self::Rejection> {
async fn from_request(req: Request<Body>, _state: &S) -> Result<Self, Self::Rejection> {
let RawForm(bytes) = req
.extract()
.await
+8 -12
View File
@@ -4,8 +4,8 @@
use axum::{
async_trait,
body::{Bytes, HttpBody},
extract::{BodyStream, FromRequest},
body::{Body, Bytes},
extract::FromRequest,
response::{IntoResponse, Response},
BoxError, RequestExt,
};
@@ -91,22 +91,18 @@ pub struct Multipart {
}
#[async_trait]
impl<S, B> FromRequest<S, B> for Multipart
impl<S> FromRequest<S> for Multipart
where
B: HttpBody + Send + 'static,
B::Data: Into<Bytes>,
B::Error: Into<BoxError>,
S: Send + Sync,
{
type Rejection = MultipartRejection;
async fn from_request(req: Request<B>, state: &S) -> Result<Self, Self::Rejection> {
async fn from_request(req: Request<Body>, _state: &S) -> Result<Self, Self::Rejection> {
let boundary = parse_boundary(req.headers()).ok_or(InvalidBoundary)?;
let stream_result = match req.with_limited_body() {
Ok(limited) => BodyStream::from_request(limited, state).await,
Err(unlimited) => BodyStream::from_request(unlimited, state).await,
let stream = match req.with_limited_body() {
Ok(limited) => Body::new(limited),
Err(unlimited) => unlimited.into_body(),
};
let stream = stream_result.unwrap_or_else(|err| match err {});
let multipart = multer::Multipart::new(stream, boundary);
Ok(Self { inner: multipart })
}
@@ -452,7 +448,7 @@ mod tests {
// No need for this to be a #[test], we just want to make sure it compiles
fn _multipart_from_request_limited() {
async fn handler(_: Multipart) {}
let _app: Router<(), http_body::Limited<Body>> = Router::new().route("/", post(handler));
let _app: Router<()> = Router::new().route("/", post(handler));
}
#[tokio::test]
+5 -5
View File
@@ -1,4 +1,5 @@
use axum::async_trait;
use axum::body::Body;
use axum::extract::{FromRequest, FromRequestParts};
use axum::response::IntoResponse;
use http::request::Parts;
@@ -109,16 +110,15 @@ impl<E, R> DerefMut for WithRejection<E, R> {
}
#[async_trait]
impl<B, E, R, S> FromRequest<S, B> for WithRejection<E, R>
impl<E, R, S> FromRequest<S> for WithRejection<E, R>
where
B: Send + 'static,
S: Send + Sync,
E: FromRequest<S, B>,
E: FromRequest<S>,
R: From<E::Rejection> + IntoResponse,
{
type Rejection = R;
async fn from_request(req: Request<B>, state: &S) -> Result<Self, Self::Rejection> {
async fn from_request(req: Request<Body>, state: &S) -> Result<Self, Self::Rejection> {
let extractor = E::from_request(req, state).await?;
Ok(WithRejection(extractor, PhantomData))
}
@@ -180,7 +180,7 @@ mod tests {
}
}
let req = Request::new(());
let req = Request::new(Body::empty());
let result = WithRejection::<TestExtractor, TestRejection>::from_request(req, &()).await;
assert!(matches!(result, Err(TestRejection)));