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

cpr::Download failed to decode downloaded content of gzip encoding #1008

Closed
amolvmisal opened this issue Jan 4, 2024 · 4 comments · Fixed by #1010
Closed

cpr::Download failed to decode downloaded content of gzip encoding #1008

amolvmisal opened this issue Jan 4, 2024 · 4 comments · Fixed by #1010
Assignees
Labels

Comments

@amolvmisal
Copy link

Description

cpr::AcceptEncoding parameter does not work when downloading with cpr::Download causing it to fail to decode the downloaded file which is a gzip encoded.

Example/How to Reproduce

cpr::Url url{"http://anyurl/file.ext"}; // Make sure response should be with 'Content-Encoding: gzip' in it
cpr::Response r = cpr::Download(of, url);
std::cout << r.header["Content-Encoding"] << std::endl; // should be 'gzip'

After downloading you can see cpr::Download failed to decode the downloaded file.

Possible Fix

Following piece of code in Session::prepareCommonDownload solved the issue;

#if LIBCURL_VERSION_NUM >= 0x072100
    if (acceptEncoding_.empty()) {
        // Enable all supported built-in compressions
        curl_easy_setopt(curl_->handle, CURLOPT_ACCEPT_ENCODING, "");
    } else if (acceptEncoding_.disabled()) {
        // Disable curl adding the 'Accept-Encoding' header
        curl_easy_setopt(curl_->handle, CURLOPT_ACCEPT_ENCODING, nullptr);
    } else {
        curl_easy_setopt(curl_->handle, CURLOPT_ACCEPT_ENCODING, acceptEncoding_.getString().c_str());
    }
#endif

This piece of code is same as in Session::prepareCommon

Where did you get it from?

GitHub (branch e.g. master)

Additional Context/Your Environment

  • OS: Linux
  • Version: 1.10.5
@COM8
Copy link
Member

COM8 commented Jan 4, 2024

Thanks @amolvmisal for reporting! I will look into it tomorrow.

@COM8 COM8 self-assigned this Jan 4, 2024
@COM8
Copy link
Member

COM8 commented Jan 5, 2024

Workaroud for while I'm working on a PR for it:

cpr::Session session;
session.SetHeader(cpr::Header{{"Accept-Encoding", "gzip"}});

@COM8
Copy link
Member

COM8 commented Jan 5, 2024

A new PR to fix this exists: #1010

Could you please verify, this fixes your issue?

@amolvmisal
Copy link
Author

@COM8 my apology for late reply and thanks for quick response.
I can confirm #1010 fixes the issue

@COM8 COM8 closed this as completed in #1010 Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants