cofetch
Chainable, high-performance async HTTP client for C++ event loops
Loading...
Searching...
No Matches
example_compression.cpp

gzip/brotli responses arrive already decoded.

gzip/brotli responses arrive already decoded.

// Compression is transparent: cofetch advertises every encoding curl
// was built with (gzip, brotli, ...), and curl decodes the response
// before it reaches you. This endpoint replies gzip-compressed — the
// body still arrives as plain JSON.
#include <cofetch.h>
#include <asio.hpp>
#include <iostream>
int main() {
asio::io_context io;
cofetch::Client http(io);
http.async_get("https://postman-echo.com/gzip",
[](std::error_code ec, const cofetch::Response& res) {
if (ec) {
std::cerr << ec.message() << "\n";
return;
}
std::cout << res.data_ << "\n"; // already decompressed
});
io.run();
}
Definition cofetch.h:266
auto async_get(std::string url, CompletionToken &&token)
Definition cofetch.h:324
Definition cofetch.h:111
std::string data_
Definition cofetch.h:177