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

https out of the box; TLS knobs via the .curl() escape hatch.

https out of the box; TLS knobs via the .curl() escape hatch.

// TLS works out of the box: https URLs are verified against the system
// CA bundle, nothing to configure. When you do need to reach the TLS
// knobs (private CA, client certificate, local dev server), the .curl()
// escape hatch exposes the raw libcurl handle per request.
#include <cofetch.h>
#include <asio.hpp>
#include <iostream>
int main() {
asio::io_context io;
cofetch::Client http(io);
http.request("https://postman-echo.com/get")
.curl([](CURL* h) {
// Examples of per-request TLS tuning (all optional):
// curl_easy_setopt(h, CURLOPT_CAINFO, "/etc/ssl/company-ca.pem");
// curl_easy_setopt(h, CURLOPT_SSLCERT, "client.pem");
// curl_easy_setopt(h, CURLOPT_SSL_VERIFYPEER, 0L); // dev only!
(void)h;
})
.get([](std::error_code ec, const cofetch::Response& res) {
if (ec) {
std::cerr << "tls/transport error: " << ec.message() << "\n";
return;
}
std::cout << "verified https: " << res.http_code_ << "\n";
});
io.run();
}
RequestBuilder & curl(std::function< void(CURL *)> fn)
Definition cofetch.h:366
Definition cofetch.h:266
RequestBuilder request(std::string url)
Start a fluent request chain: request(url).body(...).post(token).
Definition cofetch.h:412
Definition cofetch.h:111
long http_code_
Definition cofetch.h:176