ureq
ureq copied to clipboard
[Bug] In some case return empty "Content-Length" response header
In the case below, ureq return "Content-Length" response header with empty value, while did return actually with browser and curl
curl -v -A fuelup https://raw.githubusercontent.com/FuelLabs/fuelup/gh-pages/channel-fuel-beta-4.toml
ureq = "2.9.1"
use anyhow::{anyhow, Result};
use std::env;
use ureq::Response;
pub fn build_agent() -> Result<ureq::Agent> {
let agent_builder = ureq::builder().user_agent("fuelup");
if let Ok(proxy) = env::var("http_proxy") {
return Ok(agent_builder.proxy(ureq::Proxy::new(proxy)?).build());
}
Ok(agent_builder.build())
}
#[test]
fn test_agent() -> anyhow::Result<()> {
/ / this test case is used to illustrate the bug of ureq that sometimes doesn't return "Content-Length" header
let handle = build_agent()?;
let response = handle.get("https://raw.githubusercontent.com/FuelLabs/fuelup/gh-pages/channel-fuel-beta-4.toml").call()?;
assert!(response.header("Content-Length").is_none());
assert_eq!(response.status(), 200);
Ok(())
}
i'm not certain, but based on the following comment, i think ureq might ignore content-length header if the response was decoded by gzip feature. https://github.com/algesten/ureq/issues/600#issuecomment-1474169868
Hmmm... so is there one way to get the content-length through ureq in "gzip" case? I use "content-length" as a progress bar length :)
I guess we don't have a good way to do that right now.
Closing since we're moving to ureq 3.x.