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 @@ -176,7 +176,8 @@ impl Body {
176
176
/// # Ok(()) }) }
177
177
/// ```
178
178
pub async fn into_bytes ( mut self ) -> crate :: Result < Vec < u8 > > {
179
- let mut buf = Vec :: with_capacity ( 1024 ) ;
179
+ let len = usize:: try_from ( self . len ( ) . unwrap_or ( 0 ) ) . status ( StatusCode :: PayloadTooLarge ) ?;
180
+ let mut buf = Vec :: with_capacity ( len) ;
180
181
self . read_to_end ( & mut buf)
181
182
. await
182
183
. status ( StatusCode :: UnprocessableEntity ) ?;
@@ -280,9 +281,8 @@ impl Body {
280
281
/// # Ok(()) }) }
281
282
/// ```
282
283
#[ cfg( feature = "serde" ) ]
283
- pub async fn into_json < T : DeserializeOwned > ( mut self ) -> crate :: Result < T > {
284
- let mut buf = Vec :: with_capacity ( 1024 ) ;
285
- self . read_to_end ( & mut buf) . await ?;
284
+ pub async fn into_json < T : DeserializeOwned > ( self ) -> crate :: Result < T > {
285
+ let buf = self . into_bytes ( ) . await ?;
286
286
serde_json:: from_slice ( & buf) . status ( StatusCode :: UnprocessableEntity )
287
287
}
288
288
You can’t perform that action at this time.
0 commit comments