Kurlyk
Loading...
Searching...
No Matches
kurlyk::HttpRequest Class Reference

Represents an HTTP request. More...

#include <HttpRequest.hpp>

Public Member Functions

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.
 
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_url (const std::string &url, const QueryParams &query)
 Sets the request URL and appends optional query parameters.
 
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.
 
void set_accept_language (const std::string &value)
 Sets the Accept-Language header value.
 
void set_content_type (const std::string &value)
 Sets the Content-Type header value.
 
void set_origin (const std::string &value)
 Sets the Origin header value.
 
void set_referer (const std::string &value)
 Sets the Referer header value.
 
void set_proxy (const std::string &ip, int port)
 Sets the proxy server address.
 
void set_proxy (const std::string &ip, int port, ProxyType type)
 Sets the proxy server address.
 
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 set_proxy_server (const std::string &server)
 Sets the proxy server address.
 
void set_proxy_auth (const std::string &auth)
 Sets the proxy authentication credentials.
 
void set_proxy_type (ProxyType type)
 Sets the proxy type.
 
void set_proxy_auth (const std::string &username, const std::string &password)
 Sets proxy authentication credentials.
 
void set_retry_attempts (long retry_attempts, long retry_delay_ms)
 Sets the number of retry attempts and delay before retrying.
 
void add_valid_status (long status)
 Adds a single valid HTTP status code.
 
void set_valid_statuses (const std::set< long > &statuses)
 Sets the valid HTTP status codes, replacing any existing values.
 
void clear_valid_statuses ()
 Clears all valid status codes.
 
void set_user_agent (const std::string &user_agent)
 Sets the User-Agent header.
 
void set_cookie (const std::string &cookie)
 Sets the cookie data.
 
void set_cert_file (const std::string &cert_file)
 Sets the client certificate file path.
 
void set_ca_file (const std::string &ca_file)
 Sets the path to the CA certificate file.
 
void set_timeout (long timeout)
 Sets the request timeout.
 
void set_connect_timeout (long connect_timeout)
 Sets the connection timeout.
 
void set_verbose (bool verbose)
 Enables or disables verbose mode.
 
void set_debug_header (bool debug_header)
 Enables or disables debugging headers in output.
 

Public Attributes

uint64_t request_id = 0
 Unique identifier for the request (default is 0).
 
Headers headers
 HTTP request headers.
 
std::string url
 Full request URL.
 
std::string method = "GET"
 HTTP request method (e.g., "GET", "POST").
 
std::string content
 Data payload for the request.
 
std::string user_agent
 User-Agent header.
 
std::string accept_encoding
 Accept-Encoding header.
 
std::string cookie_file
 Path to the cookie file; if empty, cookies are not saved.
 
std::string cookie
 Cookie data as a string.
 
std::string cert_file
 Path to the client certificate file.
 
std::string key_file
 Path to the private key for the client certificate.
 
std::string ca_file
 Path to the CA certificate file.
 
std::string ca_path
 Path to a directory containing CA certificates.
 
std::string proxy_server
 Proxy address in <ip:port> format.
 
std::string proxy_auth
 Proxy authentication in <username:password> format.
 
ProxyType proxy_type = ProxyType::PROXY_HTTP
 Proxy type (e.g., HTTP, SOCKS5).
 
bool proxy_tunnel = true
 Enable proxy tunneling.
 
std::string interface_name
 Network interface name to use for the request.
 
bool use_interface = false
 Enable the specified network interface.
 
bool follow_location = true
 Automatically follow HTTP redirects.
 
long max_redirects = 10
 Maximum allowed redirects.
 
bool auto_referer = false
 Automatically set Referer header.
 
bool head_only = false
 If true, sends the request without a response body (HEAD-like behavior).
 
long timeout = 30
 Request timeout in seconds.
 
long connect_timeout = 10
 Connection timeout in seconds.
 
long general_rate_limit_id = 0
 ID for general rate limiting.
 
long specific_rate_limit_id = 0
 ID for specific rate limiting.
 
std::set< long > valid_statuses = {200}
 Set of valid HTTP response status codes.
 
long retry_attempts = 0
 Number of retry attempts in case of failure.
 
long retry_delay_ms = 0
 Delay between retry attempts in milliseconds.
 
bool clear_cookie_file = false
 Flag to clear the cookie file at the start of the request.
 
bool verbose = false
 Enable verbose output (CURLOPT_VERBOSE).
 
bool debug_header = false
 Include headers in debug output (CURLOPT_HEADER).
 

Detailed Description

Represents an HTTP request.

The HttpRequest class encapsulates various parameters and settings for an HTTP request, including headers, URL, method, data, and connection options. It provides methods for configuring these parameters and handling HTTP requests.

Definition at line 16 of file HttpRequest.hpp.

Member Function Documentation

◆ add_valid_status()

void kurlyk::HttpRequest::add_valid_status ( long status)
inline

Adds a single valid HTTP status code.

Parameters
statusThe HTTP status code to add to the set of valid statuses.

Definition at line 217 of file HttpRequest.hpp.

◆ clear_valid_statuses()

void kurlyk::HttpRequest::clear_valid_statuses ( )
inline

Clears all valid status codes.

Definition at line 228 of file HttpRequest.hpp.

◆ set_accept_encoding()

void kurlyk::HttpRequest::set_accept_encoding ( bool identity = false,
bool deflate = false,
bool gzip = false,
bool brotli = false )
inline

Sets the Accept-Encoding header with optional encoding types.

Parameters
identityEnable "identity" encoding.
deflateEnable "deflate" encoding.
gzipEnable "gzip" encoding.
brotliEnable "br" (brotli) encoding.

Definition at line 104 of file HttpRequest.hpp.

◆ set_accept_language()

void kurlyk::HttpRequest::set_accept_language ( const std::string & value)
inline

Sets the Accept-Language header value.

Parameters
valueThe language value to be sent with the Accept-Language header.

Definition at line 120 of file HttpRequest.hpp.

◆ set_ca_file()

void kurlyk::HttpRequest::set_ca_file ( const std::string & ca_file)
inline

Sets the path to the CA certificate file.

Parameters
ca_filePath to the CA certificate file.

Definition at line 252 of file HttpRequest.hpp.

◆ set_cert_file()

void kurlyk::HttpRequest::set_cert_file ( const std::string & cert_file)
inline

Sets the client certificate file path.

Parameters
cert_filePath to the client certificate file.

Definition at line 246 of file HttpRequest.hpp.

◆ set_connect_timeout()

void kurlyk::HttpRequest::set_connect_timeout ( long connect_timeout)
inline

Sets the connection timeout.

Parameters
connect_timeoutConnection timeout in seconds.

Definition at line 264 of file HttpRequest.hpp.

◆ set_content_type()

void kurlyk::HttpRequest::set_content_type ( const std::string & value)
inline

Sets the Content-Type header value.

Parameters
valueThe MIME type for the Content-Type header.

Definition at line 126 of file HttpRequest.hpp.

◆ set_cookie()

void kurlyk::HttpRequest::set_cookie ( const std::string & cookie)
inline

Sets the cookie data.

Parameters
cookieCookie data as a string.

Definition at line 240 of file HttpRequest.hpp.

◆ set_debug_header()

void kurlyk::HttpRequest::set_debug_header ( bool debug_header)
inline

Enables or disables debugging headers in output.

Parameters
debug_headerEnable (true) or disable (false) debug headers.

Definition at line 276 of file HttpRequest.hpp.

◆ set_origin()

void kurlyk::HttpRequest::set_origin ( const std::string & value)
inline

Sets the Origin header value.

Parameters
valueThe origin to be sent with the Origin header.

Definition at line 132 of file HttpRequest.hpp.

◆ set_proxy() [1/3]

void kurlyk::HttpRequest::set_proxy ( const std::string & ip,
int port )
inline

Sets the proxy server address.

Parameters
ipProxy server IP address.
portProxy server port.

Definition at line 145 of file HttpRequest.hpp.

◆ set_proxy() [2/3]

void kurlyk::HttpRequest::set_proxy ( const std::string & ip,
int port,
const std::string & username,
const std::string & password,
ProxyType type = ProxyType::PROXY_HTTP )
inline

Sets the proxy server address with authentication details.

Parameters
ipProxy server IP address.
portProxy server port.
usernameProxy username.
passwordProxy password.
typeProxy type.

Definition at line 169 of file HttpRequest.hpp.

◆ set_proxy() [3/3]

void kurlyk::HttpRequest::set_proxy ( const std::string & ip,
int port,
ProxyType type )
inline

Sets the proxy server address.

Parameters
ipProxy server IP address.
portProxy server port.
typeProxy type.

Definition at line 155 of file HttpRequest.hpp.

◆ set_proxy_auth() [1/2]

void kurlyk::HttpRequest::set_proxy_auth ( const std::string & auth)
inline

Sets the proxy authentication credentials.

Parameters
authProxy authentication in <username:password> format.

Definition at line 188 of file HttpRequest.hpp.

◆ set_proxy_auth() [2/2]

void kurlyk::HttpRequest::set_proxy_auth ( const std::string & username,
const std::string & password )
inline

Sets proxy authentication credentials.

Parameters
usernameProxy username.
passwordProxy password.

Definition at line 201 of file HttpRequest.hpp.

◆ set_proxy_server()

void kurlyk::HttpRequest::set_proxy_server ( const std::string & server)
inline

Sets the proxy server address.

Parameters
serverProxy address in <ip:port> format.

Definition at line 182 of file HttpRequest.hpp.

◆ set_proxy_type()

void kurlyk::HttpRequest::set_proxy_type ( ProxyType type)
inline

Sets the proxy type.

Parameters
typeType of proxy.

Definition at line 194 of file HttpRequest.hpp.

◆ set_referer()

void kurlyk::HttpRequest::set_referer ( const std::string & value)
inline

Sets the Referer header value.

Parameters
valueThe referer URL to be sent with the Referer header.

Definition at line 138 of file HttpRequest.hpp.

◆ set_retry_attempts()

void kurlyk::HttpRequest::set_retry_attempts ( long retry_attempts,
long retry_delay_ms )
inline

Sets the number of retry attempts and delay before retrying.

Parameters
retry_attemptsMaximum number of retry attempts.
retry_delay_msDelay before retrying in milliseconds.

Definition at line 210 of file HttpRequest.hpp.

◆ set_timeout()

void kurlyk::HttpRequest::set_timeout ( long timeout)
inline

Sets the request timeout.

Parameters
timeoutTimeout in seconds.

Definition at line 258 of file HttpRequest.hpp.

◆ set_url() [1/3]

void kurlyk::HttpRequest::set_url ( const std::string & host,
const std::string & path,
const QueryParams & query )
inline

Sets the request URL with host, path, and optional query parameters as a dictionary.

Parameters
hostHostname or IP address.
pathPath to resource.
queryQuery parameters in dictionary format.

Definition at line 80 of file HttpRequest.hpp.

◆ set_url() [2/3]

void kurlyk::HttpRequest::set_url ( const std::string & host,
const std::string & path,
const std::string & query = std::string() )
inline

Sets the request URL with host, path, and optional query parameters.

Parameters
hostHostname or IP address.
pathPath to resource.
queryOptional query parameters as a string.

Definition at line 61 of file HttpRequest.hpp.

◆ set_url() [3/3]

void kurlyk::HttpRequest::set_url ( const std::string & url,
const QueryParams & query )
inline

Sets the request URL and appends optional query parameters.

Parameters
urlFull request URL.
queryQuery parameters in dictionary format.

Definition at line 91 of file HttpRequest.hpp.

◆ set_user_agent()

void kurlyk::HttpRequest::set_user_agent ( const std::string & user_agent)
inline

Sets the User-Agent header.

Parameters
user_agentUser-Agent string.

Definition at line 234 of file HttpRequest.hpp.

◆ set_valid_statuses()

void kurlyk::HttpRequest::set_valid_statuses ( const std::set< long > & statuses)
inline

Sets the valid HTTP status codes, replacing any existing values.

Parameters
statusesThe new set of valid HTTP status codes.

Definition at line 223 of file HttpRequest.hpp.

◆ set_verbose()

void kurlyk::HttpRequest::set_verbose ( bool verbose)
inline

Enables or disables verbose mode.

Parameters
verboseEnable (true) or disable (false) verbose output.

Definition at line 270 of file HttpRequest.hpp.

Member Data Documentation

◆ accept_encoding

std::string kurlyk::HttpRequest::accept_encoding

Accept-Encoding header.

Definition at line 24 of file HttpRequest.hpp.

◆ auto_referer

bool kurlyk::HttpRequest::auto_referer = false

Automatically set Referer header.

Definition at line 40 of file HttpRequest.hpp.

◆ ca_file

std::string kurlyk::HttpRequest::ca_file

Path to the CA certificate file.

Definition at line 29 of file HttpRequest.hpp.

◆ ca_path

std::string kurlyk::HttpRequest::ca_path

Path to a directory containing CA certificates.

Definition at line 30 of file HttpRequest.hpp.

◆ cert_file

std::string kurlyk::HttpRequest::cert_file

Path to the client certificate file.

Definition at line 27 of file HttpRequest.hpp.

◆ clear_cookie_file

bool kurlyk::HttpRequest::clear_cookie_file = false

Flag to clear the cookie file at the start of the request.

Definition at line 51 of file HttpRequest.hpp.

◆ connect_timeout

long kurlyk::HttpRequest::connect_timeout = 10

Connection timeout in seconds.

Definition at line 44 of file HttpRequest.hpp.

◆ content

std::string kurlyk::HttpRequest::content

Data payload for the request.

Definition at line 22 of file HttpRequest.hpp.

◆ cookie

std::string kurlyk::HttpRequest::cookie

Cookie data as a string.

Definition at line 26 of file HttpRequest.hpp.

◆ cookie_file

std::string kurlyk::HttpRequest::cookie_file

Path to the cookie file; if empty, cookies are not saved.

Definition at line 25 of file HttpRequest.hpp.

◆ debug_header

bool kurlyk::HttpRequest::debug_header = false

Include headers in debug output (CURLOPT_HEADER).

Definition at line 55 of file HttpRequest.hpp.

◆ follow_location

bool kurlyk::HttpRequest::follow_location = true

Automatically follow HTTP redirects.

Definition at line 38 of file HttpRequest.hpp.

◆ general_rate_limit_id

long kurlyk::HttpRequest::general_rate_limit_id = 0

ID for general rate limiting.

Definition at line 45 of file HttpRequest.hpp.

◆ head_only

bool kurlyk::HttpRequest::head_only = false

If true, sends the request without a response body (HEAD-like behavior).

Definition at line 41 of file HttpRequest.hpp.

◆ headers

Headers kurlyk::HttpRequest::headers

HTTP request headers.

Definition at line 19 of file HttpRequest.hpp.

◆ interface_name

std::string kurlyk::HttpRequest::interface_name

Network interface name to use for the request.

Definition at line 35 of file HttpRequest.hpp.

◆ key_file

std::string kurlyk::HttpRequest::key_file

Path to the private key for the client certificate.

Definition at line 28 of file HttpRequest.hpp.

◆ max_redirects

long kurlyk::HttpRequest::max_redirects = 10

Maximum allowed redirects.

Definition at line 39 of file HttpRequest.hpp.

◆ method

std::string kurlyk::HttpRequest::method = "GET"

HTTP request method (e.g., "GET", "POST").

Definition at line 21 of file HttpRequest.hpp.

◆ proxy_auth

std::string kurlyk::HttpRequest::proxy_auth

Proxy authentication in <username:password> format.

Definition at line 32 of file HttpRequest.hpp.

◆ proxy_server

std::string kurlyk::HttpRequest::proxy_server

Proxy address in <ip:port> format.

Definition at line 31 of file HttpRequest.hpp.

◆ proxy_tunnel

bool kurlyk::HttpRequest::proxy_tunnel = true

Enable proxy tunneling.

Definition at line 34 of file HttpRequest.hpp.

◆ proxy_type

ProxyType kurlyk::HttpRequest::proxy_type = ProxyType::PROXY_HTTP

Proxy type (e.g., HTTP, SOCKS5).

Definition at line 33 of file HttpRequest.hpp.

◆ request_id

uint64_t kurlyk::HttpRequest::request_id = 0

Unique identifier for the request (default is 0).

Definition at line 18 of file HttpRequest.hpp.

◆ retry_attempts

long kurlyk::HttpRequest::retry_attempts = 0

Number of retry attempts in case of failure.

Definition at line 48 of file HttpRequest.hpp.

◆ retry_delay_ms

long kurlyk::HttpRequest::retry_delay_ms = 0

Delay between retry attempts in milliseconds.

Definition at line 49 of file HttpRequest.hpp.

◆ specific_rate_limit_id

long kurlyk::HttpRequest::specific_rate_limit_id = 0

ID for specific rate limiting.

Definition at line 46 of file HttpRequest.hpp.

◆ timeout

long kurlyk::HttpRequest::timeout = 30

Request timeout in seconds.

Definition at line 43 of file HttpRequest.hpp.

◆ url

std::string kurlyk::HttpRequest::url

Full request URL.

Definition at line 20 of file HttpRequest.hpp.

◆ use_interface

bool kurlyk::HttpRequest::use_interface = false

Enable the specified network interface.

Definition at line 36 of file HttpRequest.hpp.

◆ user_agent

std::string kurlyk::HttpRequest::user_agent

User-Agent header.

Definition at line 23 of file HttpRequest.hpp.

◆ valid_statuses

std::set<long> kurlyk::HttpRequest::valid_statuses = {200}

Set of valid HTTP response status codes.

Definition at line 47 of file HttpRequest.hpp.

◆ verbose

bool kurlyk::HttpRequest::verbose = false

Enable verbose output (CURLOPT_VERBOSE).

Definition at line 54 of file HttpRequest.hpp.


The documentation for this class was generated from the following file: