Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Halimao opened this issue Dec 21, 2023 · 3 comments
Open

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

Halimao opened this issue Dec 21, 2023 · 3 comments

Comments

@Halimao
Copy link

Halimao commented Dec 21, 2023

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

@s7tya
Copy link

s7tya commented Dec 27, 2023

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)

@Halimao
Copy link
Author

Halimao commented Dec 27, 2023

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

@algesten
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants