Skip to content

Incomplete response body using curl-client #57

@JEnoch

Description

@JEnoch

For instance, the following code doesn't print the full expected content of https://raw.githubusercontent.com/http-rs/surf/6627d9fc15437aea3c0a69e0b620ae7769ea6765/LICENSE-MIT

let url = "https://raw.githubusercontent.com/http-rs/surf/6627d9fc15437aea3c0a69e0b620ae7769ea6765/LICENSE-MIT";
let req = http_types::Request::new(http_types::Method::Get, Url::parse(url).unwrap());
let mut res: http_types::Response = http_client::isahc::IsahcClient::new().send(req).await?;
println!("{}", res.body_string().await?);

The cause of the problem is here:

http-client/src/isahc.rs

Lines 51 to 52 in 749e374

let len = body.len().map(|len| len as usize);
let body = Body::from_reader(BufReader::new(body), len);

As specified in https://docs.rs/isahc/0.9.13/isahc/struct.Body.html#method.len :

Since the length may be determined totally separately from the actual bytes, even if a value is returned it should not be relied on as always being accurate, and should be treated as a "hint"

The code shouldn't rely on it to read the response's Body.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions