1+ use crate :: body:: Body ;
12use crate :: extract:: { DefaultBodyLimitKind , FromRequest , FromRequestParts } ;
23use futures_util:: future:: BoxFuture ;
34use http:: Request ;
45use http_body:: Limited ;
56
67mod sealed {
7- pub trait Sealed < B > { }
8- impl < B > Sealed < B > for http:: Request < B > { }
8+ pub trait Sealed { }
9+ impl Sealed for http:: Request < crate :: body :: Body > { }
910}
1011
1112/// Extension trait that adds additional methods to [`Request`].
12- pub trait RequestExt < B > : sealed:: Sealed < B > + Sized {
13+ pub trait RequestExt : sealed:: Sealed + Sized {
1314 /// Apply an extractor to this `Request`.
1415 ///
1516 /// This is just a convenience for `E::from_request(req, &())`.
@@ -23,6 +24,7 @@ pub trait RequestExt<B>: sealed::Sealed<B> + Sized {
2324 /// use axum::{
2425 /// async_trait,
2526 /// extract::FromRequest,
27+ /// body::Body,
2628 /// http::{header::CONTENT_TYPE, Request, StatusCode},
2729 /// response::{IntoResponse, Response},
2830 /// Form, Json, RequestExt,
@@ -31,17 +33,16 @@ pub trait RequestExt<B>: sealed::Sealed<B> + Sized {
3133 /// struct FormOrJson<T>(T);
3234 ///
3335 /// #[async_trait]
34- /// impl<S, B, T> FromRequest<S, B > for FormOrJson<T>
36+ /// impl<S, T> FromRequest<S> for FormOrJson<T>
3537 /// where
36- /// Json<T>: FromRequest<(), B >,
37- /// Form<T>: FromRequest<(), B >,
38+ /// Json<T>: FromRequest<()>,
39+ /// Form<T>: FromRequest<()>,
3840 /// T: 'static,
39- /// B: Send + 'static,
4041 /// S: Send + Sync,
4142 /// {
4243 /// type Rejection = Response;
4344 ///
44- /// async fn from_request(req: Request<B >, _state: &S) -> Result<Self, Self::Rejection> {
45+ /// async fn from_request(req: Request<Body >, _state: &S) -> Result<Self, Self::Rejection> {
4546 /// let content_type = req
4647 /// .headers()
4748 /// .get(CONTENT_TYPE)
@@ -70,7 +71,7 @@ pub trait RequestExt<B>: sealed::Sealed<B> + Sized {
7071 /// ```
7172 fn extract < E , M > ( self ) -> BoxFuture < ' static , Result < E , E :: Rejection > >
7273 where
73- E : FromRequest < ( ) , B , M > + ' static ,
74+ E : FromRequest < ( ) , M > + ' static ,
7475 M : ' static ;
7576
7677 /// Apply an extractor that requires some state to this `Request`.
@@ -85,6 +86,7 @@ pub trait RequestExt<B>: sealed::Sealed<B> + Sized {
8586 /// ```
8687 /// use axum::{
8788 /// async_trait,
89+ /// body::Body,
8890 /// extract::{FromRef, FromRequest},
8991 /// http::Request,
9092 /// RequestExt,
@@ -95,15 +97,14 @@ pub trait RequestExt<B>: sealed::Sealed<B> + Sized {
9597 /// }
9698 ///
9799 /// #[async_trait]
98- /// impl<S, B > FromRequest<S, B > for MyExtractor
100+ /// impl<S> FromRequest<S> for MyExtractor
99101 /// where
100102 /// String: FromRef<S>,
101103 /// S: Send + Sync,
102- /// B: Send + 'static,
103104 /// {
104105 /// type Rejection = std::convert::Infallible;
105106 ///
106- /// async fn from_request(req: Request<B >, state: &S) -> Result<Self, Self::Rejection> {
107+ /// async fn from_request(req: Request<Body >, state: &S) -> Result<Self, Self::Rejection> {
107108 /// let requires_state = req.extract_with_state::<RequiresState, _, _>(state).await?;
108109 ///
109110 /// Ok(Self { requires_state })
@@ -114,22 +115,21 @@ pub trait RequestExt<B>: sealed::Sealed<B> + Sized {
114115 /// struct RequiresState { /* ... */ }
115116 ///
116117 /// #[async_trait]
117- /// impl<S, B > FromRequest<S, B > for RequiresState
118+ /// impl<S> FromRequest<S> for RequiresState
118119 /// where
119120 /// String: FromRef<S>,
120121 /// S: Send + Sync,
121- /// B: Send + 'static,
122122 /// {
123123 /// // ...
124124 /// # type Rejection = std::convert::Infallible;
125- /// # async fn from_request(req: Request<B >, _state: &S) -> Result<Self, Self::Rejection> {
125+ /// # async fn from_request(req: Request<Body >, _state: &S) -> Result<Self, Self::Rejection> {
126126 /// # todo!()
127127 /// # }
128128 /// }
129129 /// ```
130130 fn extract_with_state < E , S , M > ( self , state : & S ) -> BoxFuture < ' _ , Result < E , E :: Rejection > >
131131 where
132- E : FromRequest < S , B , M > + ' static ,
132+ E : FromRequest < S , M > + ' static ,
133133 S : Send + Sync ;
134134
135135 /// Apply a parts extractor to this `Request`.
@@ -145,6 +145,7 @@ pub trait RequestExt<B>: sealed::Sealed<B> + Sized {
145145 /// headers::{authorization::Bearer, Authorization},
146146 /// http::Request,
147147 /// response::{IntoResponse, Response},
148+ /// body::Body,
148149 /// Json, RequestExt, TypedHeader,
149150 /// };
150151 ///
@@ -154,16 +155,15 @@ pub trait RequestExt<B>: sealed::Sealed<B> + Sized {
154155 /// }
155156 ///
156157 /// #[async_trait]
157- /// impl<S, B, T> FromRequest<S, B > for MyExtractor<T>
158+ /// impl<S, T> FromRequest<S> for MyExtractor<T>
158159 /// where
159- /// B: Send + 'static,
160160 /// S: Send + Sync,
161- /// Json<T>: FromRequest<(), B >,
161+ /// Json<T>: FromRequest<()>,
162162 /// T: 'static,
163163 /// {
164164 /// type Rejection = Response;
165165 ///
166- /// async fn from_request(mut req: Request<B >, _state: &S) -> Result<Self, Self::Rejection> {
166+ /// async fn from_request(mut req: Request<Body >, _state: &S) -> Result<Self, Self::Rejection> {
167167 /// let TypedHeader(auth_header) = req
168168 /// .extract_parts::<TypedHeader<Authorization<Bearer>>>()
169169 /// .await
@@ -197,6 +197,7 @@ pub trait RequestExt<B>: sealed::Sealed<B> + Sized {
197197 /// extract::{FromRef, FromRequest, FromRequestParts},
198198 /// http::{request::Parts, Request},
199199 /// response::{IntoResponse, Response},
200+ /// body::Body,
200201 /// Json, RequestExt,
201202 /// };
202203 ///
@@ -206,17 +207,16 @@ pub trait RequestExt<B>: sealed::Sealed<B> + Sized {
206207 /// }
207208 ///
208209 /// #[async_trait]
209- /// impl<S, B, T> FromRequest<S, B > for MyExtractor<T>
210+ /// impl<S, T> FromRequest<S> for MyExtractor<T>
210211 /// where
211212 /// String: FromRef<S>,
212- /// Json<T>: FromRequest<(), B >,
213+ /// Json<T>: FromRequest<()>,
213214 /// T: 'static,
214215 /// S: Send + Sync,
215- /// B: Send + 'static,
216216 /// {
217217 /// type Rejection = Response;
218218 ///
219- /// async fn from_request(mut req: Request<B >, state: &S) -> Result<Self, Self::Rejection> {
219+ /// async fn from_request(mut req: Request<Body >, state: &S) -> Result<Self, Self::Rejection> {
220220 /// let requires_state = req
221221 /// .extract_parts_with_state::<RequiresState, _>(state)
222222 /// .await
@@ -260,29 +260,26 @@ pub trait RequestExt<B>: sealed::Sealed<B> + Sized {
260260 /// Apply the [default body limit](crate::extract::DefaultBodyLimit).
261261 ///
262262 /// If it is disabled, return the request as-is in `Err`.
263- fn with_limited_body ( self ) -> Result < Request < Limited < B > > , Request < B > > ;
263+ fn with_limited_body ( self ) -> Result < Request < Limited < Body > > , Request < Body > > ;
264264
265265 /// Consumes the request, returning the body wrapped in [`Limited`] if a
266266 /// [default limit](crate::extract::DefaultBodyLimit) is in place, or not wrapped if the
267267 /// default limit is disabled.
268- fn into_limited_body ( self ) -> Result < Limited < B > , B > ;
268+ fn into_limited_body ( self ) -> Result < Limited < Body > , Body > ;
269269}
270270
271- impl < B > RequestExt < B > for Request < B >
272- where
273- B : Send + ' static ,
274- {
271+ impl RequestExt for Request < Body > {
275272 fn extract < E , M > ( self ) -> BoxFuture < ' static , Result < E , E :: Rejection > >
276273 where
277- E : FromRequest < ( ) , B , M > + ' static ,
274+ E : FromRequest < ( ) , M > + ' static ,
278275 M : ' static ,
279276 {
280277 self . extract_with_state ( & ( ) )
281278 }
282279
283280 fn extract_with_state < E , S , M > ( self , state : & S ) -> BoxFuture < ' _ , Result < E , E :: Rejection > >
284281 where
285- E : FromRequest < S , B , M > + ' static ,
282+ E : FromRequest < S , M > + ' static ,
286283 S : Send + Sync ,
287284 {
288285 E :: from_request ( self , state)
@@ -324,7 +321,7 @@ where
324321 } )
325322 }
326323
327- fn with_limited_body ( self ) -> Result < Request < Limited < B > > , Request < B > > {
324+ fn with_limited_body ( self ) -> Result < Request < Limited < Body > > , Request < Body > > {
328325 // update docs in `axum-core/src/extract/default_body_limit.rs` and
329326 // `axum/src/docs/extract.md` if this changes
330327 const DEFAULT_LIMIT : usize = 2_097_152 ; // 2 mb
@@ -338,7 +335,7 @@ where
338335 }
339336 }
340337
341- fn into_limited_body ( self ) -> Result < Limited < B > , B > {
338+ fn into_limited_body ( self ) -> Result < Limited < Body > , Body > {
342339 self . with_limited_body ( )
343340 . map ( Request :: into_body)
344341 . map_err ( Request :: into_body)
@@ -354,11 +351,10 @@ mod tests {
354351 } ;
355352 use async_trait:: async_trait;
356353 use http:: Method ;
357- use hyper:: Body ;
358354
359355 #[ tokio:: test]
360356 async fn extract_without_state ( ) {
361- let req = Request :: new ( ( ) ) ;
357+ let req = Request :: new ( Body :: empty ( ) ) ;
362358
363359 let method: Method = req. extract ( ) . await . unwrap ( ) ;
364360
@@ -376,7 +372,7 @@ mod tests {
376372
377373 #[ tokio:: test]
378374 async fn extract_with_state ( ) {
379- let req = Request :: new ( ( ) ) ;
375+ let req = Request :: new ( Body :: empty ( ) ) ;
380376
381377 let state = "state" . to_owned ( ) ;
382378
@@ -387,7 +383,10 @@ mod tests {
387383
388384 #[ tokio:: test]
389385 async fn extract_parts_without_state ( ) {
390- let mut req = Request :: builder ( ) . header ( "x-foo" , "foo" ) . body ( ( ) ) . unwrap ( ) ;
386+ let mut req = Request :: builder ( )
387+ . header ( "x-foo" , "foo" )
388+ . body ( Body :: empty ( ) )
389+ . unwrap ( ) ;
391390
392391 let method: Method = req. extract_parts ( ) . await . unwrap ( ) ;
393392
@@ -397,7 +396,10 @@ mod tests {
397396
398397 #[ tokio:: test]
399398 async fn extract_parts_with_state ( ) {
400- let mut req = Request :: builder ( ) . header ( "x-foo" , "foo" ) . body ( ( ) ) . unwrap ( ) ;
399+ let mut req = Request :: builder ( )
400+ . header ( "x-foo" , "foo" )
401+ . body ( Body :: empty ( ) )
402+ . unwrap ( ) ;
401403
402404 let state = "state" . to_owned ( ) ;
403405
@@ -417,15 +419,14 @@ mod tests {
417419 }
418420
419421 #[ async_trait]
420- impl < S , B > FromRequest < S , B > for WorksForCustomExtractor
422+ impl < S > FromRequest < S > for WorksForCustomExtractor
421423 where
422424 S : Send + Sync ,
423- B : Send + ' static ,
424- String : FromRef < S > + FromRequest < ( ) , B > ,
425+ String : FromRef < S > + FromRequest < ( ) > ,
425426 {
426- type Rejection = <String as FromRequest < ( ) , B > >:: Rejection ;
427+ type Rejection = <String as FromRequest < ( ) > >:: Rejection ;
427428
428- async fn from_request ( mut req : Request < B > , state : & S ) -> Result < Self , Self :: Rejection > {
429+ async fn from_request ( mut req : Request < Body > , state : & S ) -> Result < Self , Self :: Rejection > {
429430 let RequiresState ( from_state) = req. extract_parts_with_state ( state) . await . unwrap ( ) ;
430431 let method = req. extract_parts ( ) . await . unwrap ( ) ;
431432 let body = req. extract ( ) . await ?;
0 commit comments