2#ifndef _KURLYK_WEBSOCKET_CONFIG_HPP_INCLUDED
3#define _KURLYK_WEBSOCKET_CONFIG_HPP_INCLUDED
49 void set_url(
const std::string& host,
const std::string& path,
const std::string& query =
"") {
51 if (!path.empty() && path[0] !=
'/') {
56 url += (query[0] ==
'?' ?
"" :
"?") + query;
72 void set_accept_encoding(
bool identity =
false,
bool deflate =
false,
bool gzip =
false,
bool brotli =
false) {
73 std::string encodings;
74 if (identity) encodings +=
"identity";
75 if (deflate) encodings += (encodings.empty() ?
"" :
",") + std::string(
"deflate");
76 if (gzip) encodings += (encodings.empty() ?
"" :
",") + std::string(
"gzip");
77 if (brotli) encodings += (encodings.empty() ?
"" :
",") + std::string(
"br");
122 const std::string& ip,
124 const std::string& username,
125 const std::string& password,
158 this->headers.emplace(
"Accept-Language", accept_language);
209 rate_limits.emplace_back(requests_per_period, period_ms);
217 long period_ms = 60000;
225 long period_ms = 1000;
Configuration parameters for establishing and managing WebSocket connections.
void set_cookie(const std::string &cookie)
Sets the cookie data.
void set_verify_cert(bool verify_cert)
Sets whether to verify the server’s certificate.
ProxyType proxy_type
Proxy type (e.g., HTTP, SOCKS5).
std::string accept_encoding
Accept-Encoding header.
long add_rate_limit_rpm(long requests_per_minute)
Adds a rate limit based on Requests Per Minute (RPM).
void set_reconnect(bool reconnect, long reconnect_attempts=0, long reconnect_delay=0)
Configures reconnection behavior.
std::string proxy_server
Proxy address in <ip:port> format.
void set_proxy(const std::string &ip, int port)
Sets the proxy server address.
long idle_timeout
Maximum idle time for the WebSocket connection in seconds (0 means no timeout).
std::string user_agent
User-Agent header.
std::string ca_file
Path to the Root CA certificate file.
void set_proxy_type(ProxyType type)
Sets the proxy type.
long reconnect_attempts
Number of reconnection attempts (0 means infinite attempts).
std::string url
URL of the WebSocket server.
void set_proxy_auth(const std::string &auth)
Sets the proxy authentication credentials.
std::vector< RateLimitData > rate_limits
List of rate limits applied to WebSocket messages.
std::string cert_file
Path to the client certificate file.
Headers headers
HTTP headers included in the WebSocket connection request.
void set_url(const std::string &host, const std::string &path, const std::string &query="")
Sets the WebSocket server URL with optional query parameters.
long add_rate_limit_rps(long requests_per_second)
Adds a rate limit based on Requests Per Second (RPS).
void set_proxy(const std::string &ip, int port, ProxyType type)
Sets the proxy server address.
void set_accept_language(const std::string &accept_language)
Sets the Accept-Language header.
std::string cookie
Cookie data as a string.
bool verify_cert
If true, verifies the server’s certificate and hostname according to RFC 2818.
void set_idle_timeout(long idle_timeout)
Configures the idle timeout for the WebSocket connection.
void set_proxy(const std::string &ip, int port, const std::string &username, const std::string &password, ProxyType type=ProxyType::PROXY_HTTP)
Sets the proxy server address with authentication.
std::string proxy_auth
Proxy authentication in <username:password> format.
void set_ca_file(const std::string &ca_file)
Sets the path to the CA certificate file.
void set_request_timeout(long request_timeout)
Sets the timeout for WebSocket requests.
long reconnect_delay
Delay in seconds between reconnection attempts.
void set_user_agent(const std::string &user_agent)
Sets the User-Agent header.
bool reconnect
Enables automatic reconnection if true.
long add_rate_limit(long requests_per_period, long period_ms)
Adds a rate limit configuration to control the frequency of WebSocket messages.
long request_timeout
Timeout for WebSocket requests in seconds (0 means no timeout).
std::string key_file
Path to the private key file corresponding to the client certificate.
void set_ca_file(bool verify_cert, const std::string &ca_file)
Sets certificate verification and sets the CA certificate file.
void set_proxy_auth(const std::string &username, const std::string &password)
Configures proxy authentication credentials.
void set_proxy_server(const std::string &server)
Sets the proxy server address.
std::vector< std::string > protocols
List of subprotocols for the Sec-WebSocket-Protocol header.
void set_accept_encoding(bool identity=false, bool deflate=false, bool gzip=false, bool brotli=false)
Sets the Accept-Encoding header with specified encodings.
void set_url(const std::string &url, const QueryParams &query)
Sets the WebSocket server URL with specified query parameters.
std::string to_query_string(const QueryParams &query, const std::string &prefix=std::string()) noexcept
Converts a map of query parameters into a URL query string.
Primary namespace for the Kurlyk library, encompassing initialization, request management,...
ProxyType
Enumeration of supported proxy types compatible with libcurl.
utils::CaseInsensitiveMultimap Headers
Alias for HTTP headers, providing a case-insensitive unordered multimap.
utils::CaseInsensitiveMultimap QueryParams
Alias for query parameters in HTTP requests, stored case-insensitively.
RateLimitData(long requests_per_period=0, long period_ms=0)
long period_ms
Time period in milliseconds for the request limit.
long requests_per_period
Maximum number of requests allowed per period.