improve http fallouts, move to its own class

This commit is contained in:
proddy
2026-08-29 16:26:26 +02:00
parent 4d4d716e5f
commit db5ccb018f
7 changed files with 204 additions and 108 deletions
+2 -1
View File
@@ -20,6 +20,7 @@
#include "WebCommandService.h"
#include "shuntingYard.h"
#include "httpClient.h"
namespace emsesp {
@@ -267,7 +268,7 @@ bool WebCommandService::executeCommand(const char * name, const std::string & co
auto lower_url = Helpers::toLower(url.c_str());
if (lower_url.starts_with("http://") || lower_url.starts_with("https://")) {
std::string result;
int httpResult = http_request(url, method, value, doc["header"].as<JsonObjectConst>(), result);
int httpResult = HttpClient::request(url, method, value, doc["header"].as<JsonObjectConst>(), result);
if (httpResult != 200) {
EMSESP::logger().warning("Command '%s': URL command failed with http code %d", name, httpResult);
return false;
+3 -5
View File
@@ -20,10 +20,8 @@
#ifndef EMSESP_STANDALONE
#include <esp_ota_ops.h>
#include <WiFiClient.h>
#include <ESP_SSLClient.h>
#endif
#include "shuntingYard.h"
#include "httpClient.h"
namespace emsesp {
@@ -427,9 +425,9 @@ bool WebStatusService::refresh_versions_cache() {
#else
std::string result;
JsonDocument doc;
auto http_code = http_request(VERSIONS_URL, "GET", "", doc.as<JsonObjectConst>(), result);
auto http_code = HttpClient::request(VERSIONS_URL, "GET", "", doc.as<JsonObjectConst>(), result);
if (http_code != 200) {
EMSESP::logger().warning("refresh_versions_cache() HTTP error code %d", http_code);
EMSESP::logger().warning("Unable to retrieve online version information (HTTP error code %d)", http_code);
return false;
}
DeserializationError err = deserializeJson(doc, result);