@@ -93,6 +93,7 @@ impl Request {
9393 }
9494
9595 /// Get the remote address for this request.
96+ ///
9697 /// This is determined in the following priority:
9798 /// 1. `Forwarded` header `for` key
9899 /// 2. The first `X-Forwarded-For` header
@@ -102,6 +103,7 @@ impl Request {
102103 }
103104
104105 /// Get the destination host for this request.
106+ ///
105107 /// This is determined in the following priority:
106108 /// 1. `Forwarded` header `host` key
107109 /// 2. The first `X-Forwarded-Host` header
@@ -304,8 +306,9 @@ impl Request {
304306 /// assert_eq!(&req.body_string().await.unwrap(), "Hello Nori");
305307 /// # Ok(()) }) }
306308 /// ```
307- pub async fn body_string ( self ) -> crate :: Result < String > {
308- self . body . into_string ( ) . await
309+ pub async fn body_string ( & mut self ) -> crate :: Result < String > {
310+ let body = self . take_body ( ) ;
311+ body. into_string ( ) . await
309312 }
310313
311314 /// Read the body as bytes.
@@ -329,8 +332,9 @@ impl Request {
329332 /// assert_eq!(bytes, vec![1, 2, 3]);
330333 /// # Ok(()) }) }
331334 /// ```
332- pub async fn body_bytes ( self ) -> crate :: Result < Vec < u8 > > {
333- self . body . into_bytes ( ) . await
335+ pub async fn body_bytes ( & mut self ) -> crate :: Result < Vec < u8 > > {
336+ let body = self . take_body ( ) ;
337+ body. into_bytes ( ) . await
334338 }
335339
336340 /// Read the body as JSON.
@@ -358,8 +362,9 @@ impl Request {
358362 /// assert_eq!(&cat.name, "chashu");
359363 /// # Ok(()) }) }
360364 /// ```
361- pub async fn body_json < T : DeserializeOwned > ( self ) -> crate :: Result < T > {
362- self . body . into_json ( ) . await
365+ pub async fn body_json < T : DeserializeOwned > ( & mut self ) -> crate :: Result < T > {
366+ let body = self . take_body ( ) ;
367+ body. into_json ( ) . await
363368 }
364369
365370 /// Read the body as `x-www-form-urlencoded`.
@@ -387,8 +392,9 @@ impl Request {
387392 /// assert_eq!(&cat.name, "chashu");
388393 /// # Ok(()) }) }
389394 /// ```
390- pub async fn body_form < T : DeserializeOwned > ( self ) -> crate :: Result < T > {
391- self . body . into_form ( ) . await
395+ pub async fn body_form < T : DeserializeOwned > ( & mut self ) -> crate :: Result < T > {
396+ let body = self . take_body ( ) ;
397+ body. into_form ( ) . await
392398 }
393399
394400 /// Get an HTTP header.
0 commit comments