chore: auto-commit (13 archivos)
- CMakeLists.txt - agent_protocol.cpp - agent_protocol.h - app.md - appicon.ico - hosts_db.cpp - hosts_db.h - http_client.cpp - http_client.h - main.cpp - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#include "http_client.h"
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user