Kurlyk
Toggle main menu visibility
Loading...
Searching...
No Matches
proxy_checker_example.cpp
Go to the documentation of this file.
1
#include <
kurlyk.hpp
>
2
3
#include <chrono>
4
#include <iostream>
5
#include <string>
6
7
int
main
(
int
argc,
char
* argv[]) {
8
if
(argc < 2) {
9
std::cout <<
"Usage: proxy_checker_example <host:port> [test-url]"
<< std::endl;
10
return
0;
11
}
12
13
kurlyk::ProxyConfig
proxy;
14
proxy.
proxy_server
= argv[1];
15
proxy.
proxy_type
=
kurlyk::ProxyType::PROXY_HTTP
;
16
proxy.
use
=
true
;
17
18
kurlyk::ProxyCheckOptions
options;
19
if
(argc >= 3) options.
test_url
= argv[2];
20
21
const
kurlyk::ProxyCheckResult
result =
kurlyk::check_proxy
(proxy, options).get();
22
23
std::cout
24
<<
"reachable: "
<< std::boolalpha << result.
reachable
<<
'\n'
25
<<
"http_ok: "
<< result.
http_ok
<<
'\n'
26
<<
"https_ok: "
<< result.
https_ok
<<
'\n'
27
<<
"status: "
<< result.
http_status
<<
'\n'
28
<<
"connect: "
<< result.
connect_latency_ms
<<
" ms\n"
29
<<
"tls/connect: "
<< result.
tls_latency_ms
<<
" ms\n"
30
<<
"ttfb: "
<< result.
ttfb_ms
<<
" ms\n"
31
<<
"total: "
<< result.
total_latency_ms
<<
" ms\n"
;
32
33
if
(result.
error_code
) {
34
std::cerr <<
"error: "
<< result.
error_code
.message();
35
if
(!result.
error_message
.empty()) {
36
std::cerr <<
" ("
<< result.
error_message
<<
')'
;
37
}
38
std::cerr << std::endl;
39
return
1;
40
}
41
return
result.
http_ok
? 0 : 2;
42
}
main
int main()
Definition
api_key_auth_provider_example.cpp:5
kurlyk.hpp
Main header file for the Kurlyk library, providing HTTP and WebSocket support.
kurlyk::ProxyType::PROXY_HTTP
@ PROXY_HTTP
HTTP proxy.
Definition
enums.hpp:13
kurlyk::check_proxy
std::future< ProxyCheckResult > check_proxy(const ProxyConfig &proxy, const ProxyCheckOptions &options=ProxyCheckOptions())
Starts an asynchronous no-body request through a proxy.
Definition
ProxyChecker.hpp:189
kurlyk::ProxyCheckOptions
Configures the no-body request used to check a proxy.
Definition
ProxyCheckOptions.hpp:14
kurlyk::ProxyCheckOptions::test_url
std::string test_url
HTTP or HTTPS URL requested through the proxy.
Definition
ProxyCheckOptions.hpp:15
kurlyk::ProxyCheckResult
Stores proxy reachability, protocol status, errors, and curl timing metrics.
Definition
ProxyCheckResult.hpp:15
kurlyk::ProxyCheckResult::error_message
std::string error_message
Error details supplied by the HTTP backend.
Definition
ProxyCheckResult.hpp:21
kurlyk::ProxyCheckResult::reachable
bool reachable
True when an HTTP response was received through the proxy.
Definition
ProxyCheckResult.hpp:16
kurlyk::ProxyCheckResult::tls_latency_ms
long tls_latency_ms
TLS setup time after TCP connect, in milliseconds; includes proxy CONNECT negotiation.
Definition
ProxyCheckResult.hpp:25
kurlyk::ProxyCheckResult::error_code
std::error_code error_code
Transport, HTTP, or client-side error.
Definition
ProxyCheckResult.hpp:20
kurlyk::ProxyCheckResult::total_latency_ms
long total_latency_ms
Total request time, in milliseconds.
Definition
ProxyCheckResult.hpp:27
kurlyk::ProxyCheckResult::connect_latency_ms
long connect_latency_ms
Elapsed time until the TCP connection was established, in milliseconds.
Definition
ProxyCheckResult.hpp:24
kurlyk::ProxyCheckResult::http_ok
bool http_ok
True when the test endpoint returned a 2xx or 3xx response.
Definition
ProxyCheckResult.hpp:17
kurlyk::ProxyCheckResult::ttfb_ms
long ttfb_ms
Elapsed time until the first response byte, in milliseconds.
Definition
ProxyCheckResult.hpp:26
kurlyk::ProxyCheckResult::https_ok
bool https_ok
True when an HTTPS test returned a 2xx or 3xx response.
Definition
ProxyCheckResult.hpp:18
kurlyk::ProxyCheckResult::http_status
long http_status
HTTP status returned by the test endpoint or proxy.
Definition
ProxyCheckResult.hpp:22
kurlyk::ProxyConfig
Stores proxy server, authentication, and transport settings.
Definition
ProxyConfig.hpp:23
kurlyk::ProxyConfig::proxy_type
ProxyType proxy_type
Proxy transport type.
Definition
ProxyConfig.hpp:26
kurlyk::ProxyConfig::proxy_server
std::string proxy_server
Proxy address in host:port format.
Definition
ProxyConfig.hpp:24
kurlyk::ProxyConfig::use
bool use
Indicates whether the proxy is enabled.
Definition
ProxyConfig.hpp:27
examples
proxy_checker_example.cpp
Generated by
1.18.0