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
- fix: curl - avoid zero-sized HEAD bodies If there is no body then don't construct a zero-lengthed body. Fixes: https://github.com/http-rs/surf/issues/321 Fixes: https://github.com/http-rs/surf/issue... — committed to Fishrock123/http-client by Fishrock123 3 years ago
- fix: curl - avoid zero-sized HEAD bodies If there is no body then don't construct a zero-lengthed body. Fixes: https://github.com/http-rs/surf/issues/321 Fixes: https://github.com/http-rs/surf/issue... — committed to Fishrock123/http-client by Fishrock123 3 years ago
- fix: curl - avoid zero-sized HEAD bodies If there is no body then don't construct a zero-lengthed body. Fixes: https://github.com/http-rs/surf/issues/321 Fixes: https://github.com/http-rs/surf/issue... — committed to Fishrock123/http-client by Fishrock123 3 years ago
Tested with:
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 onSome(0) | None =>
because in some cases it does a Some(0) which would still triger the other path.https://github.com/sagebind/isahc/issues/341