Skip to content

Commit 737308f

Browse files
committed
http get example: switch to read_to_end
1 parent 372e366 commit 737308f

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

examples/http_get.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
1717
.ok_or_else(|| "response expected to have Content-Type header")?;
1818
assert_eq!(content_type, "application/json; charset=utf-8");
1919

20-
// Would much prefer read_to_end here:
21-
let mut body_buf = vec![0; 4096];
22-
let body_len = response.body().read(&mut body_buf).await?;
23-
body_buf.truncate(body_len);
20+
let mut body_buf = Vec::new();
21+
let _body_len = response.body().read_to_end(&mut body_buf).await?;
2422

2523
let val: serde_json::Value = serde_json::from_slice(&body_buf)?;
2624
let body_url = val

0 commit comments

Comments
 (0)