Kurlyk
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
7int 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
14 proxy.proxy_server = argv[1];
16 proxy.use = true;
17
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 header file for the Kurlyk library, providing HTTP and WebSocket support.
@ PROXY_HTTP
HTTP proxy.
Definition enums.hpp:13
std::future< ProxyCheckResult > check_proxy(const ProxyConfig &proxy, const ProxyCheckOptions &options=ProxyCheckOptions())
Starts an asynchronous no-body request through a proxy.
Configures the no-body request used to check a proxy.
std::string test_url
HTTP or HTTPS URL requested through the proxy.
Stores proxy reachability, protocol status, errors, and curl timing metrics.
std::string error_message
Error details supplied by the HTTP backend.
bool reachable
True when an HTTP response was received through the proxy.
long tls_latency_ms
TLS setup time after TCP connect, in milliseconds; includes proxy CONNECT negotiation.
std::error_code error_code
Transport, HTTP, or client-side error.
long total_latency_ms
Total request time, in milliseconds.
long connect_latency_ms
Elapsed time until the TCP connection was established, in milliseconds.
bool http_ok
True when the test endpoint returned a 2xx or 3xx response.
long ttfb_ms
Elapsed time until the first response byte, in milliseconds.
bool https_ok
True when an HTTPS test returned a 2xx or 3xx response.
long http_status
HTTP status returned by the test endpoint or proxy.
Stores proxy server, authentication, and transport settings.
ProxyType proxy_type
Proxy transport type.
std::string proxy_server
Proxy address in host:port format.
bool use
Indicates whether the proxy is enabled.