algesten / ureq

A simple, safe HTTP client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Halimao opened this issue · 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

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.
#600 (comment)

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.