Skip to content

HEAD requests which return a content-length incorrectly Err #321

@Firstyear

Description

@Firstyear

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions