#include "http.hpp" #include #include #include int main(int argc, char** argv) { if ((argc != 4 && argc != 5) || 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]); if (argc == 5) limits.max_response_bytes = std::stoul(argv[4]); 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(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(); }