http-rs / http-rs/surf

HEAD requests which return a content-length incorrectly Err

Open
#321 15 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
1.5k
Forks
128
PR merge metrics
No merged PRs in 30d

Description

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:

```toml
[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"]
```

```rust
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.

Contributor guide

Open the contributing guide

Research direction

Start with Surf's handling of HEAD responses and run the provided async-std reproducer against the openSUSE URL. Done means the request succeeds when a HEAD response includes Content-Length, without reporting a response-body error; add or run a regression test if the repository provides a suitable test location.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.