struct
#include <include/coeurl/client.hpp>
Client Global information, common to all connections.
Public static functions
- static void set_logger(std::shared_ptr<spdlog::logger> logger)
- Set a global logger.
Constructors, destructors, conversion operators
Public functions
- void operator=(Client const&) deleted
- Uncopyable.
- void operator=(Client&&) deleted
- Unmoveable.
- void submit_request(std::shared_ptr<Request> conn)
- Submit a manually created request.
- void shutdown()
- Stop all currently running requests.
- void close(bool force = false)
- Stop the event loop. If you force close it, all pending requests are cancelled.
- void get(std::string url, std::function<void(const Request&)> callback, const Headers& headers = {}, long max_redirects = 0)
- Make a simple GET request. For more complicated requests, create it manually and call submit_request.
- void delete_(std::string url, std::function<void(const Request&)> callback, const Headers& headers = {}, long max_redirects = 0)
- Make a simple DELETE request.
- void delete_(std::string url, std::string request_body, std::string mimetype, std::function<void(const Request&)> callback, const Headers& headers = {}, long max_redirects = 0)
- Make a simple DELETE request with a body.
- void head(std::string url, std::function<void(const Request&)> callback, const Headers& headers = {}, long max_redirects = 0)
- Make a simple HEAD request. For more complicated requests, create it manually and call submit_request.
- void options(std::string url, std::function<void(const Request&)> callback, const Headers& headers = {}, long max_redirects = 0)
- Make a simple OPTIONS request. For more complicated requests, create it manually and call submit_request.
- void put(std::string url, std::string request_body, std::string mimetype, std::function<void(const Request&)> callback, const Headers& headers = {}, long max_redirects = 0)
- Make a simple PUT request with a body.
- void post(std::string url, std::string request_body, std::string mimetype, std::function<void(const Request&)> callback, const Headers& headers = {}, long max_redirects = 0)
- Make a simple POST request with a body.
- void set_verify_peer(bool verify)
- Set whether to verify the https certificates or not.
- auto does_verify_peer() const -> bool
- Query whether certificate verification is enabled or not.
- void verbose(bool verbose)
- Set whether or not to log curl requests verbosely.
- auto verbose() const -> bool
- Query whether verbose logging is enabled or not.
- void connection_timeout(long t)
- Timeout connection after the specified amount of seconds, if the server stops sending acks.
- void maximum_total_connections(long count)
- Maximum connections to open in parallel for this client. Set to 0 to disable the limit. Default is 64.
- void maximum_connections_per_host(long count)
- Maximum connections to open in parallel for each specific host for this client. Set to 0 to disable the limit. Default is 8.
- void alt_svc_cache_path(const std::string& path)
- Cache alternative service entries. This allows automatically switching to http/3. Usually you provide a path in
~/.cache
or similar. - auto alt_svc_cache_path() const -> const std::string&
- Where alternate svc entries are cached. Usually in
~/.cache
.
Function documentation
static void coeurl:: Client:: set_logger(std::shared_ptr<spdlog::logger> logger)
Set a global logger.
Parameters | |
---|---|
logger | The spdlog logger to use for logging. |
Set the logger while no requests are in flight, for example before starting the first request.
void coeurl:: Client:: get(std::string url,
std::function<void(const Request&)> callback,
const Headers& headers = {},
long max_redirects = 0)
Make a simple GET request. For more complicated requests, create it manually and call submit_request.
Parameters | |
---|---|
url | The url to request. |
callback | The callback, which will be called after the request is completed. The request will be passed as a parameter, which you can use to access the response. |
headers | Headers to use for this request. Defaults to none. |
max_redirects | How many redirects to follow. Defaults to none. |
void coeurl:: Client:: delete_(std::string url,
std::function<void(const Request&)> callback,
const Headers& headers = {},
long max_redirects = 0)
Make a simple DELETE request.
Parameters | |
---|---|
url | The url to request. |
callback | The callback, which will be called after the request is completed. The request will be passed as a parameter, which you can use to access the response. |
headers | Headers to use for this request. Defaults to none. |
max_redirects | How many redirects to follow. Defaults to none. |
void coeurl:: Client:: delete_(std::string url,
std::string request_body,
std::string mimetype,
std::function<void(const Request&)> callback,
const Headers& headers = {},
long max_redirects = 0)
Make a simple DELETE request with a body.
Parameters | |
---|---|
url | The url to request. |
request_body | The body to use with this request. |
mimetype | The mimetype of the request_body. |
callback | The callback, which will be called after the request is completed. The request will be passed as a parameter, which you can use to access the response. |
headers | Headers to use for this request. Defaults to none. |
max_redirects | How many redirects to follow. Defaults to none. |
void coeurl:: Client:: head(std::string url,
std::function<void(const Request&)> callback,
const Headers& headers = {},
long max_redirects = 0)
Make a simple HEAD request. For more complicated requests, create it manually and call submit_request.
Parameters | |
---|---|
url | The url to request. |
callback | The callback, which will be called after the request is completed. The request will be passed as a parameter, which you can use to access the response. |
headers | Headers to use for this request. Defaults to none. |
max_redirects | How many redirects to follow. Defaults to none. |
void coeurl:: Client:: options(std::string url,
std::function<void(const Request&)> callback,
const Headers& headers = {},
long max_redirects = 0)
Make a simple OPTIONS request. For more complicated requests, create it manually and call submit_request.
Parameters | |
---|---|
url | The url to request. |
callback | The callback, which will be called after the request is completed. The request will be passed as a parameter, which you can use to access the response. |
headers | Headers to use for this request. Defaults to none. |
max_redirects | How many redirects to follow. Defaults to none. |
void coeurl:: Client:: put(std::string url,
std::string request_body,
std::string mimetype,
std::function<void(const Request&)> callback,
const Headers& headers = {},
long max_redirects = 0)
Make a simple PUT request with a body.
Parameters | |
---|---|
url | The url to request. |
request_body | The body to use with this request. |
mimetype | The mimetype of the request_body. |
callback | The callback, which will be called after the request is completed. The request will be passed as a parameter, which you can use to access the response. |
headers | Headers to use for this request. Defaults to none. |
max_redirects | How many redirects to follow. Defaults to none. |
void coeurl:: Client:: post(std::string url,
std::string request_body,
std::string mimetype,
std::function<void(const Request&)> callback,
const Headers& headers = {},
long max_redirects = 0)
Make a simple POST request with a body.
Parameters | |
---|---|
url | The url to request. |
request_body | The body to use with this request. |
mimetype | The mimetype of the request_body. |
callback | The callback, which will be called after the request is completed. The request will be passed as a parameter, which you can use to access the response. |
headers | Headers to use for this request. Defaults to none. |
max_redirects | How many redirects to follow. Defaults to none. |
bool coeurl:: Client:: does_verify_peer() const
Query whether certificate verification is enabled or not.
void coeurl:: Client:: verbose(bool verbose)
Set whether or not to log curl requests verbosely.
bool coeurl:: Client:: verbose() const
Query whether verbose logging is enabled or not.