@@ -93,6 +93,7 @@ impl Request {
93
93
}
94
94
95
95
/// Get the remote address for this request.
96
+ ///
96
97
/// This is determined in the following priority:
97
98
/// 1. `Forwarded` header `for` key
98
99
/// 2. The first `X-Forwarded-For` header
@@ -102,6 +103,7 @@ impl Request {
102
103
}
103
104
104
105
/// Get the destination host for this request.
106
+ ///
105
107
/// This is determined in the following priority:
106
108
/// 1. `Forwarded` header `host` key
107
109
/// 2. The first `X-Forwarded-Host` header
@@ -304,8 +306,9 @@ impl Request {
304
306
/// assert_eq!(&req.body_string().await.unwrap(), "Hello Nori");
305
307
/// # Ok(()) }) }
306
308
/// ```
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
309
312
}
310
313
311
314
/// Read the body as bytes.
@@ -329,8 +332,9 @@ impl Request {
329
332
/// assert_eq!(bytes, vec![1, 2, 3]);
330
333
/// # Ok(()) }) }
331
334
/// ```
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
334
338
}
335
339
336
340
/// Read the body as JSON.
@@ -358,8 +362,9 @@ impl Request {
358
362
/// assert_eq!(&cat.name, "chashu");
359
363
/// # Ok(()) }) }
360
364
/// ```
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
363
368
}
364
369
365
370
/// Read the body as `x-www-form-urlencoded`.
@@ -387,8 +392,9 @@ impl Request {
387
392
/// assert_eq!(&cat.name, "chashu");
388
393
/// # Ok(()) }) }
389
394
/// ```
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
392
398
}
393
399
394
400
/// Get an HTTP header.
0 commit comments