surf: HEAD requests which return a content-length incorrectly Err

Some urls will return a content-length during head requests. Surf incorrectly assumes that this means there is a body present and will error:

thread 'main' panicked at 'Should Succeed!: ResponseBodyError(None): unknown error', src/main.rs:9:28
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The following reproducer can show this behaviour:

[package]
name = "surf-cl-repro"
version = "0.1.0"
edition = "2018"
[dependencies]
surf = "2.2"
url = "2"
[dependencies.async-std]
version = "1.7.0"
features = ["attributes"]
use url::Url;

#[async_std::main]
async fn main() {
    let client = surf::client().with(surf::middleware::Redirect::new(2));
    let url = Url::parse("http://download.opensuse.org/update/tumbleweed/repodata/repomd.xml")
        .expect("invalid url");
    let req = surf::head(url);
    client.send(req).await.expect("Should Succeed!");
}

Expected Results: Surf should allow head requests to proceed even if a content-length is returned.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 15 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Tested with:

[patch.crates-io]
http-client = { git = "https://github.com/Fishrock123/http-client.git", branch = "fix-isahc-head-zero-size" }

Can confirm that it works now 😃

Thank you!

@Fishrock123 I think I’ve solved it. Looking at http-client/src/isahc.rs I think you need to match on Some(0) | None => because in some cases it does a Some(0) which would still triger the other path.