47 lines
2.1 KiB
C++
47 lines
2.1 KiB
C++
#ifndef XENITH_HTTP_CLIENT_H
|
|
#define XENITH_HTTP_CLIENT_H
|
|
// http_client.h — минимальный HTTP-клиент для проверки обновлений.
|
|
//
|
|
// В проекте заявлено «без внешних зависимостей», а cpp-httplib требует OpenSSL
|
|
// для HTTPS. Поэтому запросы делаются через внешний инструмент с каскадом
|
|
// запасных вариантов: curl → wget → python3 → git.
|
|
// Каждый аргумент экранируется, поэтому инъекция в shell невозможна.
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace xt {
|
|
|
|
struct HttpResponse {
|
|
bool ok = false; // true если получен ответ (даже 4xx/5xx)
|
|
int status = 0; // HTTP-код; 0 = запрос не удался
|
|
std::string body;
|
|
std::string error; // человекочитаемая причина неудачи
|
|
std::string via; // каким инструментом выполнен ("curl", "wget", "python3")
|
|
};
|
|
|
|
struct HttpOptions {
|
|
int timeout_sec = 15;
|
|
bool verify_tls = true;
|
|
std::vector<std::pair<std::string,std::string>> headers; // например Authorization
|
|
bool follow = true; // следовать редиректам
|
|
};
|
|
|
|
// GET-запрос. Возвращает ответ первого сработавшего инструмента.
|
|
HttpResponse http_get(const std::string& url, const HttpOptions& opt = {});
|
|
|
|
// Скачать файл (для архивов/ассетов).
|
|
bool http_download(const std::string& url, const std::string& dest_path,
|
|
const HttpOptions& opt, std::string& err, std::string* via = nullptr);
|
|
|
|
// Какой инструмент доступен (для диагностики и `xenith doctor`).
|
|
std::vector<std::string> http_available_tools();
|
|
|
|
// Безопасное экранирование аргумента для /bin/sh.
|
|
std::string shell_quote(const std::string& s);
|
|
|
|
} // namespace xt
|
|
|
|
#endif // XENITH_HTTP_CLIENT_H
|