#include "http_client.h" #include #include namespace pex_http { // Stub: usa curl via popen igual que llm_anthropic. Reemplazar por // fn_http::request cuando el helper del registry exista (issue 0110). Response request(const Request& req) { Response resp; if (req.url.empty()) { resp.error = "empty url"; return resp; } std::string cmd = "curl -sS --max-time " + std::to_string(req.timeout_ms / 1000) + " -X " + (req.method.empty() ? "GET" : req.method); if (!req.bearer_token.empty()) { cmd += " -H \"Authorization: Bearer " + req.bearer_token + "\""; } for (const auto& kv : req.headers) { cmd += " -H \"" + kv.first + ": " + kv.second + "\""; } if (!req.body.empty()) { cmd += " --data-binary @-"; } cmd += " -w \"\\n__STATUS__%{http_code}\" \"" + req.url + "\""; FILE* fp = popen(cmd.c_str(), "r"); if (!fp) { resp.error = "popen failed"; return resp; } char buf[4096]; while (fgets(buf, sizeof(buf), fp)) resp.body += buf; pclose(fp); auto pos = resp.body.rfind("\n__STATUS__"); if (pos != std::string::npos) { try { resp.status = std::stoi(resp.body.substr(pos + 11)); } catch (...) {} resp.body.resize(pos); } return resp; } } // namespace pex_http