sagebind / isahc

The practical HTTP client that is fun to use.

Home Page:https://docs.rs/isahc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

head requests with content length fail

Firstyear opened this issue · comments

http-rs/surf#321

Using isahc as a backend to surf, I noted that doing head requests to servers which return a content length fail due to no body being present. The surf developers isolated this to isahc, but they also noted they are using 0.9.

Is this behaviour fixed in 1.0? Or would it be a valid issue in 1.0 as well?

Thanks!

Thanks for bringing this to my attention! In particular, I think this might be what is causing Surf to error:

fn main() -> Result<(), isahc::Error> {
    let response = isahc::head("http://download.opensuse.org/update/tumbleweed/repodata/repomd.xml")?;

    println!("Status: {}", response.status());
    println!("Headers: {:#?}", response.headers());
    println!("Body is empty: {}", response.body().is_empty()); // This should be true, but is false instead

    Ok(())
}

Isahc doesn't throw any errors, but it is returning a streaming body (which happens to return no bytes) instead of an "empty" body. Reproduced with 1.5.0.

I can backport a fix to 0.9.x as well if Surf really wants to avoid upgrading.

It might be best for @Fishrock123 to comment on the 0.9 backport :)

Thanks so much for finding the cause so quickly!

Turns out this actually isn't the underlying problem with the Surf issue in question, #342 is, but this bug deserves to be fixed too! I'll leave this issue open to focus on Body::is_empty not returning true when it should.

This is now fixed in the 1.5.1 release.