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 {
173173 /// # Ok(()) }) }
174174 /// ```
175175 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) ;
177178 self . read_to_end ( & mut buf) . await . status ( StatusCode :: UnprocessableEntity ) ?;
178179 Ok ( buf)
179180 }
@@ -273,9 +274,8 @@ impl Body {
273274 /// # Ok(()) }) }
274275 /// ```
275276 #[ 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 ?;
279279 serde_json:: from_slice ( & buf) . status ( StatusCode :: UnprocessableEntity )
280280 }
281281
You can’t perform that action at this time.
0 commit comments