Drop HTTP/proxy mirror types; speak Void::Net directly

Delete Api::HttpMethod/Header/Request/Response/ProxyConfig/ProxyType +
RetryConfig — they duplicated Void::Net::* and Void::Retry. INetworkClient
now takes/returns Void::Net::Request/Response/Header/ProxyConfig (retry
tuning drops off the public interface; it was unused and lives inside the
client now). NetworkConfig.proxy becomes Void::Net::ProxyConfig, and
NetworkTypes.hpp is a thin forwarder to <Void/Net/Http.hpp>.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 4.8 committed 2026-06-23 13:49:26 +03:00
1 parent a2de8c63ce
commit 85c0377e87
3 files changed
+25 -187

No files matched your search

+1 -1
View File
@@ -57,7 +57,7 @@ namespace Echoion::Api
// Network & Proxy Settings
struct NetworkConfig {
std::optional<ProxyConfig> proxy;
std::optional<Void::Net::ProxyConfig> proxy;
bool rpcEnabled = true;
uint16_t rpcPort = 8765;
std::string rpcBindAddress = "127.0.0.1";
@@ -1,7 +1,7 @@
#pragma once
#include "NetworkTypes.hpp"
#include "Types.hpp"
#include <Void/Net/Http.hpp>
#include <future>
#include <optional>
#include <string>
@@ -10,7 +10,8 @@
namespace Echoion::Api
{
// Network client interface
// Network client interface. Speaks Void::Net types directly — there is no
// echoion-side HTTP/proxy mirror.
class INetworkClient
{
public:
@@ -19,38 +20,36 @@ namespace Echoion::Api
// Initialize with optional proxy
virtual Result<void> initialize(
const std::optional<ProxyConfig>& proxy = std::nullopt) = 0;
const std::optional<Void::Net::ProxyConfig>& proxy =
std::nullopt) = 0;
virtual void shutdown() = 0;
// Synchronous requests
[[nodiscard]] virtual Result<HttpResponse>
[[nodiscard]] virtual Result<Void::Net::Response>
get(std::string_view url,
const std::vector<HttpHeader>& headers = {}) = 0;
[[nodiscard]] virtual Result<HttpResponse>
const std::vector<Void::Net::Header>& headers = {}) = 0;
[[nodiscard]] virtual Result<Void::Net::Response>
post(std::string_view url, std::string_view body,
const std::vector<HttpHeader>& headers = {}) = 0;
[[nodiscard]] virtual Result<HttpResponse>
request(const HttpRequest& req) = 0;
const std::vector<Void::Net::Header>& headers = {}) = 0;
[[nodiscard]] virtual Result<Void::Net::Response>
request(const Void::Net::Request& req) = 0;
// Asynchronous requests
[[nodiscard]] virtual std::future<Result<HttpResponse>>
[[nodiscard]] virtual std::future<Result<Void::Net::Response>>
getAsync(std::string_view url,
const std::vector<HttpHeader>& headers = {}) = 0;
[[nodiscard]] virtual std::future<Result<HttpResponse>>
const std::vector<Void::Net::Header>& headers = {}) = 0;
[[nodiscard]] virtual std::future<Result<Void::Net::Response>>
postAsync(std::string_view url, std::string_view body,
const std::vector<HttpHeader>& headers = {}) = 0;
[[nodiscard]] virtual std::future<Result<HttpResponse>>
requestAsync(const HttpRequest& req) = 0;
const std::vector<Void::Net::Header>& headers = {}) = 0;
[[nodiscard]] virtual std::future<Result<Void::Net::Response>>
requestAsync(const Void::Net::Request& req) = 0;
// Proxy configuration
virtual void setProxy(const std::optional<ProxyConfig>& proxy) = 0;
[[nodiscard]] virtual std::optional<ProxyConfig>
virtual void
setProxy(const std::optional<Void::Net::ProxyConfig>& proxy) = 0;
[[nodiscard]] virtual std::optional<Void::Net::ProxyConfig>
getProxy() const = 0;
virtual void clearProxy() = 0;
// Retry configuration
virtual void setRetryConfig(const RetryConfig& config) = 0;
[[nodiscard]] virtual RetryConfig getRetryConfig() const = 0;
};
} // namespace Echoion::Api
+4 -165
View File
@@ -1,167 +1,6 @@
#pragma once
#include "Types.hpp"
#include <cctype>
#include <chrono>
#include <map>
#include <optional>
#include <string>
#include <vector>
namespace Echoion::Api
{
enum class HttpMethod : uint8_t {
GET = 0,
POST,
PUT,
DELETE,
PATCH,
HEAD,
OPTIONS
};
enum class ProxyType : uint8_t { HTTP = 0, SOCKS5 };
struct ProxyConfig {
ProxyType type = ProxyType::HTTP;
std::string host;
uint16_t port;
std::optional<std::string> username;
std::optional<std::string> password;
std::optional<std::chrono::milliseconds> timeout;
[[nodiscard]] bool isValid() const noexcept
{
return !host.empty() && port > 0;
}
[[nodiscard]] bool requiresAuth() const noexcept
{
return username.has_value() && password.has_value();
}
[[nodiscard]] bool isSocks5() const noexcept
{
return type == ProxyType::SOCKS5;
}
[[nodiscard]] bool
operator==(const ProxyConfig& other) const = default;
[[nodiscard]] bool
operator!=(const ProxyConfig& other) const = default;
};
struct HttpHeader {
std::string name;
std::string value;
};
struct HttpRequest {
std::string url;
HttpMethod method = HttpMethod::GET;
std::vector<HttpHeader> headers;
std::optional<std::vector<uint8_t>> body;
std::optional<ProxyConfig> proxy;
std::chrono::milliseconds timeout = 30000ms;
bool followRedirects = true;
uint32_t maxRedirects = 10;
};
struct HttpResponse {
int32_t statusCode;
// Using vector to support multiple headers with same name (e.g.,
// Set-Cookie)
std::vector<std::pair<std::string, std::string>> headers;
std::string body;
std::chrono::milliseconds responseTime;
std::optional<std::string> contentType;
bool fromCache = false;
[[nodiscard]] bool isSuccess() const noexcept
{
return statusCode >= 200 && statusCode < 300;
}
[[nodiscard]] bool isRedirect() const noexcept
{
return statusCode >= 300 && statusCode < 400;
}
[[nodiscard]] bool isError() const noexcept
{
return statusCode >= 400 || statusCode == 0;
}
[[nodiscard]] std::string bodyAsString() const
{
return std::string(body.begin(), body.end());
}
// Helper to get first header value by name (case-insensitive)
[[nodiscard]] std::optional<std::string>
getHeader(std::string_view name) const
{
for (const auto& [key, value] : headers) {
if (key.size() == name.size()) {
bool match = true;
for (size_t i = 0; i < key.size(); ++i) {
if (std::tolower(
static_cast<unsigned char>(key[i])) !=
std::tolower(
static_cast<unsigned char>(name[i]))) {
match = false;
break;
}
}
if (match) {
return value;
}
}
}
return std::nullopt;
}
// Helper to get all header values by name (case-insensitive) -
// useful for Set-Cookie
[[nodiscard]] std::vector<std::string>
getHeaders(std::string_view name) const
{
std::vector<std::string> result;
for (const auto& [key, value] : headers) {
if (key.size() == name.size()) {
bool match = true;
for (size_t i = 0; i < key.size(); ++i) {
if (std::tolower(
static_cast<unsigned char>(key[i])) !=
std::tolower(
static_cast<unsigned char>(name[i]))) {
match = false;
break;
}
}
if (match) {
result.push_back(value);
}
}
}
return result;
}
};
struct RateLimitInfo {
uint32_t limit;
uint32_t remaining;
std::optional<std::chrono::system_clock::time_point> resetTime;
};
struct RetryConfig {
uint32_t maxRetries = 3;
std::chrono::milliseconds initialDelay = 1000ms;
std::chrono::milliseconds maxDelay = 30000ms;
float backoffMultiplier = 2.0f;
std::vector<int32_t> retryableStatusCodes = {408, 429, 500,
502, 503, 504};
};
} // namespace Echoion::Api
// echoion no longer mirrors HTTP/proxy types — they are Void::Net's. This
// header forwards to Void::Net so existing includes keep resolving
// Void::Net::Request / Response / Header / Method / ProxyConfig.
#include <Void/Net/Http.hpp>