ureq icon indicating copy to clipboard operation
ureq copied to clipboard

[Bug] In some case return empty "Content-Length" response header

Open Halimao opened this issue 1 year ago • 3 comments

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(())
}

image

Halimao avatar Dec 21 '23 02:12 Halimao

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

s7tya avatar Dec 27 '23 05:12 s7tya

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 :)

Halimao avatar Dec 27 '23 11:12 Halimao

I guess we don't have a good way to do that right now.

algesten avatar Jan 13 '24 10:01 algesten

Closing since we're moving to ureq 3.x.

algesten avatar Aug 13 '24 18:08 algesten