libcpr / cpr

C++ Requests: Curl for People, a spiritual port of Python Requests.
https://docs.libcpr.org/
Other
6.29k stars 903 forks source link

INTERNAL_ERROR(4) on any requests that goes to a site protected with CloudFlare #1069

Open veteri opened 3 days ago

veteri commented 3 days ago

Description

If you perform a simple get requests to any site that isnt using CloudFlare, everything is fine and works as expected. However if you do the same with any site using cloudflare, the response has a status_code of 0 and INTERNAL_ERROR(4).

Example/How to Reproduce

This will result in the above mentioned INTERNAL_ERROR

cpr::Url url{ "https://discord.com" };
cpr::Session session;
session.SetOption(url);

cpr::Response r = session.Get();

std::cout << "Status code: " << r.status_code << '\n';
std::cout << "Header:\n";
if (r.status_code == 0) {

    std::cout << "Error code: " << r.error.message << '\n';
}
for (const std::pair<std::string, std::string>& kv : r.header) {
    std::cout << '\t' << kv.first << ':' << kv.second << '\n';
}
std::cout << "Text: " << r.text << '\n';

This will work fine:

cpr::Url url{ "https://google.com" };
cpr::Session session;
session.SetOption(url);

cpr::Response r = session.Get();

std::cout << "Status code: " << r.status_code << '\n';
std::cout << "Header:\n";
if (r.status_code == 0) {

    std::cout << "Error code: " << r.error.message << '\n';
}
for (const std::pair<std::string, std::string>& kv : r.header) {
    std::cout << '\t' << kv.first << ':' << kv.second << '\n';
}
std::cout << "Text: " << r.text << '\n';

Possible Fix

No response

Where did you get it from?

vcpkg

Additional Context/Your Environment

COM8 commented 1 day ago

@veteri thanks for reporting. I will try to look into it over the weekend.

prabuinet commented 1 day ago

I faced the same issue with a cmake+vcpkg project,

It worked fine after downgrading to version 1.9.3

vcpkg.json:

{ "name": "app", "version-string": "1.0.0", "dependencies": [ { "name": "nlohmann-json" }, { "name": "fmt" }, { "name": "spdlog" }, { "name": "sdl2" }, { "name": "cpr" }, { "name": "ixwebsocket" }, { "name": "concurrentqueue" }, { "name": "sdl2-mixer" }, { "name": "cryptopp" }, { "name": "sqlite3" }, { "name": "openssl" }, { "name": "opengl" }, { "name": "boost-algorithm" } ], "overrides": [ { "name": "cpr", "version": "1.9.3" } ], "builtin-baseline": "04b0cf2b3fd1752d3c3db969cbc10ba0a4613cee" }

COM8 commented 24 minutes ago

I can not confirm this issue. For me on Linux (Fedora) with all combinations (cpr master, 1.10.5 and curl 8.4.0 and 8.8.0) it works. I'm not using vcpkg. vcpkg is not maintained by us so, I don't know how they do it.

That's what I used: https://github.com/libcpr/example-cmake-fetch-content