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 {
176176 /// # Ok(()) }) }
177177 /// ```
178178 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) ;
180181 self . read_to_end ( & mut buf)
181182 . await
182183 . status ( StatusCode :: UnprocessableEntity ) ?;
@@ -280,9 +281,8 @@ impl Body {
280281 /// # Ok(()) }) }
281282 /// ```
282283 #[ 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 ?;
286286 serde_json:: from_slice ( & buf) . status ( StatusCode :: UnprocessableEntity )
287287 }
288288
You can’t perform that action at this time.
0 commit comments