Files
tws-zombies-scripts/tools/tests/http_probe.cpp
T
josh 1121b44857 Organize scripts and add TWS plugins with HTTP timeouts
Vendor pinned T5 and T6 plugin sources under the new plugins layout. Add native HTTP deadlines, status and timing diagnostics, telemetry integration, and build/test tooling.
2026-10-09 11:02:20 -04:00

27 lines
1.3 KiB
C++

#include "http.hpp"
#include <chrono>
#include <cstdlib>
#include <iostream>
int main(int argc, char** argv)
{
if (argc != 4 || curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK)
return 2;
utils::http::timeouts limits;
// A dash exercises the defaults compiled into the actual plugin source.
if (std::string(argv[2]) != "-") limits.connect_timeout_ms = std::stol(argv[2]);
if (std::string(argv[3]) != "-") limits.timeout_ms = std::stol(argv[3]);
const auto started = std::chrono::steady_clock::now();
const auto result = utils::http::get_data(argv[1], "{\"event\":\"heartbeat\"}",
{{"Content-Type", "application/json"}, {"Authorization", "Bearer test-only"}}, "POST", limits);
const auto wall_ms = std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - started).count();
if (!result) return 3;
std::cout << "{\"curl_code\":" << result->code << ",\"http_status\":" << result->status
<< ",\"dns_ms\":" << result->dns_ms << ",\"connect_ms\":" << result->connect_ms
<< ",\"tls_ms\":" << result->tls_ms << ",\"first_byte_ms\":" << result->first_byte_ms
<< ",\"total_ms\":" << result->total_ms << ",\"wall_ms\":" << wall_ms
<< ",\"body_size\":" << result->buffer.size() << "}\n";
curl_global_cleanup();
}