File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -173,7 +173,8 @@ impl Body {
173
173
/// # Ok(()) }) }
174
174
/// ```
175
175
pub async fn into_bytes ( mut self ) -> crate :: Result < Vec < u8 > > {
176
- let mut buf = Vec :: with_capacity ( 1024 ) ;
176
+ let len = usize:: try_from ( self . len ( ) . unwrap_or ( 0 ) ) . status ( StatusCode :: PayloadTooLarge ) ?;
177
+ let mut buf = Vec :: with_capacity ( len) ;
177
178
self . read_to_end ( & mut buf) . await . status ( StatusCode :: UnprocessableEntity ) ?;
178
179
Ok ( buf)
179
180
}
@@ -273,9 +274,8 @@ impl Body {
273
274
/// # Ok(()) }) }
274
275
/// ```
275
276
#[ cfg( feature = "serde" ) ]
276
- pub async fn into_json < T : DeserializeOwned > ( mut self ) -> crate :: Result < T > {
277
- let mut buf = Vec :: with_capacity ( 1024 ) ;
278
- self . read_to_end ( & mut buf) . await ?;
277
+ pub async fn into_json < T : DeserializeOwned > ( self ) -> crate :: Result < T > {
278
+ let buf = self . into_bytes ( ) . await ?;
279
279
serde_json:: from_slice ( & buf) . status ( StatusCode :: UnprocessableEntity )
280
280
}
281
281
You can’t perform that action at this time.
0 commit comments