2#ifndef _KURLYK_HTTP_REQUEST_HPP_INCLUDED
3#define _KURLYK_HTTP_REQUEST_HPP_INCLUDED
62 const std::string& host,
63 const std::string& path,
64 const std::string& query = std::string()) {
66 if (!path.empty() && path[0] !=
'/') {
71 if (query[0] !=
'?')
url +=
"?";
81 const std::string& host,
82 const std::string& path,
95 this->url += args_str;
105 bool identity =
false,
106 bool deflate =
false,
108 bool brotli =
false) {
109 std::string encodings;
110 if (identity) encodings +=
"identity";
111 if (deflate) encodings += (encodings.empty() ?
"" :
",") + std::string(
"deflate");
112 if (gzip) encodings += (encodings.empty() ?
"" :
",") + std::string(
"gzip");
113 if (brotli) encodings += (encodings.empty() ?
"" :
",") + std::string(
"br");
121 headers.emplace(
"Accept-Language", value);
127 headers.emplace(
"Content-Type", value);
133 headers.emplace(
"Origin", value);
139 headers.emplace(
"Referer", value);
146 const std::string& ip,
156 const std::string& ip,
170 const std::string& ip,
172 const std::string& username,
173 const std::string& password,
202 const std::string& username,
203 const std::string& password) {
Represents an HTTP request.
bool proxy_tunnel
Enable proxy tunneling.
std::string user_agent
User-Agent header.
long specific_rate_limit_id
ID for specific rate limiting.
std::string proxy_auth
Proxy authentication in <username:password> format.
void set_proxy_type(ProxyType type)
Sets the proxy type.
long timeout
Request timeout in seconds.
void set_verbose(bool verbose)
Enables or disables verbose mode.
bool head_only
If true, sends the request without a response body (HEAD-like behavior).
void set_cert_file(const std::string &cert_file)
Sets the client certificate file path.
void set_proxy_auth(const std::string &auth)
Sets the proxy authentication credentials.
bool follow_location
Automatically follow HTTP redirects.
bool debug_header
Include headers in debug output (CURLOPT_HEADER).
long connect_timeout
Connection timeout in seconds.
std::string cert_file
Path to the client certificate file.
bool verbose
Enable verbose output (CURLOPT_VERBOSE).
void set_retry_attempts(long retry_attempts, long retry_delay_ms)
Sets the number of retry attempts and delay before retrying.
void set_proxy_server(const std::string &server)
Sets the proxy server address.
bool use_interface
Enable the specified network interface.
void set_referer(const std::string &value)
Sets the Referer header value.
void set_ca_file(const std::string &ca_file)
Sets the path to the CA certificate file.
std::string url
Full request URL.
std::string interface_name
Network interface name to use for the request.
void set_timeout(long timeout)
Sets the request timeout.
std::string content
Data payload for the request.
std::string cookie_file
Path to the cookie file; if empty, cookies are not saved.
void set_proxy(const std::string &ip, int port, ProxyType type)
Sets the proxy server address.
void set_proxy_auth(const std::string &username, const std::string &password)
Sets proxy authentication credentials.
void set_url(const std::string &host, const std::string &path, const QueryParams &query)
Sets the request URL with host, path, and optional query parameters as a dictionary.
void set_valid_statuses(const std::set< long > &statuses)
Sets the valid HTTP status codes, replacing any existing values.
std::string proxy_server
Proxy address in <ip:port> format.
std::string cookie
Cookie data as a string.
void set_cookie(const std::string &cookie)
Sets the cookie data.
long general_rate_limit_id
ID for general rate limiting.
uint64_t request_id
Unique identifier for the request (default is 0).
long retry_delay_ms
Delay between retry attempts in milliseconds.
ProxyType proxy_type
Proxy type (e.g., HTTP, SOCKS5).
Headers headers
HTTP request headers.
void set_connect_timeout(long connect_timeout)
Sets the connection timeout.
void set_url(const std::string &url, const QueryParams &query)
Sets the request URL and appends optional query parameters.
void set_proxy(const std::string &ip, int port)
Sets the proxy server address.
bool auto_referer
Automatically set Referer header.
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 details.
void clear_valid_statuses()
Clears all valid status codes.
void set_content_type(const std::string &value)
Sets the Content-Type header value.
void set_accept_encoding(bool identity=false, bool deflate=false, bool gzip=false, bool brotli=false)
Sets the Accept-Encoding header with optional encoding types.
std::string accept_encoding
Accept-Encoding header.
void set_accept_language(const std::string &value)
Sets the Accept-Language header value.
std::string ca_file
Path to the CA certificate file.
long retry_attempts
Number of retry attempts in case of failure.
std::string key_file
Path to the private key for the client certificate.
void set_origin(const std::string &value)
Sets the Origin header value.
bool clear_cookie_file
Flag to clear the cookie file at the start of the request.
void set_url(const std::string &host, const std::string &path, const std::string &query=std::string())
Sets the request URL with host, path, and optional query parameters.
long max_redirects
Maximum allowed redirects.
std::string ca_path
Path to a directory containing CA certificates.
std::set< long > valid_statuses
Set of valid HTTP response status codes.
std::string method
HTTP request method (e.g., "GET", "POST").
void set_debug_header(bool debug_header)
Enables or disables debugging headers in output.
void set_user_agent(const std::string &user_agent)
Sets the User-Agent header.
void add_valid_status(long status)
Adds a single valid HTTP status code.
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.
std::unique_ptr< HttpRequest > HttpRequestPtr
A unique pointer to an HttpRequest object for memory management.
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.