Skip to content
Snippets Groups Projects
Verified Commit d97acd1a authored by Nicolas Werner's avatar Nicolas Werner
Browse files

Add altsvc support

This allows the connection to discover http/3 ports.
parent cfeae3ac
No related branches found
No related tags found
No related merge requests found
Pipeline #3942 failed
......@@ -26,7 +26,7 @@ option(USE_BUNDLED_SPDLOG "Use the bundled version of spdlog." ${HUNTER_ENABLED}
project(coeurl
VERSION 0.2.1
VERSION 0.3.0
DESCRIPTION "Simple library to do http requests asynchronously via CURL in C++."
HOMEPAGE_URL "https://nheko.im/nheko-reborn/cocurl")
......
......@@ -27,7 +27,7 @@ struct SockInfo;
//! Global information, common to all connections
struct Client {
//! construct a new client
//! construct a new client. For http/3 support, set the alt_svc_cache_path as well.
Client();
/// @brief cleans up a client
/// Implicitly closes the connection and blocks until all of them exited.
......@@ -151,6 +151,12 @@ struct Client {
//! Default is 8.
void maximum_connections_per_host(long count);
//! Cache alternative service entries. This allows automatically switching to http/3.
//! Usually you provide a path in `~/.cache` or similar.
void alt_svc_cache_path(const std::string &path) { alt_svc_cache_path_ = path; }
//! Where alternate svc entries are cached. Usually in `~/.cache`.
const std::string &alt_svc_cache_path() const { return alt_svc_cache_path_; }
private:
// Call this to run the event loop. Will block until the client is shutdown.
void run();
......@@ -196,6 +202,8 @@ struct Client {
std::thread bg_thread;
std::string alt_svc_cache_path_;
friend Request;
};
} // namespace coeurl
......@@ -125,6 +125,11 @@ Request::Request(Client *client, Method m, std::string url__) : url_(std::move(u
curl_easy_setopt(this->easy, CURLOPT_XFERINFOFUNCTION, prog_cb);
curl_easy_setopt(this->easy, CURLOPT_XFERINFODATA, this);
curl_easy_setopt(this->easy, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
// enable altsvc support, which allows us to switch to http3
curl_easy_setopt(this->easy, CURLOPT_ALTSVC_CTRL, CURLALTSVC_H1|CURLALTSVC_H2|CURLALTSVC_H3);
curl_easy_setopt(this->easy, CURLOPT_ALTSVC, client->alt_svc_cache_path().c_str());
// default to all supported encodings
curl_easy_setopt(this->easy, CURLOPT_ACCEPT_ENCODING, "");
......
project('coeurl', 'cpp',
version : '0.2.1',
version : '0.3.0',
license : 'MIT',
meson_version : '>=0.54',
default_options : ['warning_level=3', 'cpp_std=c++17']
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment