Net: pinned resolver callback and cancellation for HttpClient::send (closes #55)

This commit is contained in:
faumaray committed 2026-12-04 06:10:43 +03:00
1 parent 5c5fe96f11
commit 4a820748dd
3 files changed
+230 -6

No files matched your search

+13
View File
@@ -101,8 +101,18 @@ namespace Void::Net
std::vector<Header> headers;
std::optional<std::string> body;
std::chrono::seconds timeout{30};
/// Cancels an in-flight request; the call returns a cancelled error.
std::stop_token stop{};
};
/// Resolve-then-connect hook. Receives the host and port and returns the
/// addresses (IPv4/IPv6 literals) the client must connect to. This lets a
/// caller validate every resolved answer and pin it, closing the DNS
/// rebinding window between validation and connect. An empty result is a
/// connect failure.
using ResolveHook = std::function<Void::Result::Result<std::vector<std::string>>(
std::string_view host, std::uint16_t port)>;
struct Response {
std::uint16_t status = 0;
std::vector<Header> headers;
@@ -146,6 +156,8 @@ namespace Void::Net
std::uint64_t max_body_size{64ULL * 1024 * 1024};
int max_redirects{0};
bool allow_insecure_redirects{false};
/// Optional pinned resolver applied to direct connections.
ResolveHook resolve{};
};
struct TransferProgress {
@@ -311,6 +323,7 @@ namespace Void::Net
std::uint64_t m_max_body = 64ull * 1024 * 1024;
int m_max_redirects = 0;
bool m_allow_insecure_redirects = false;
ResolveHook m_resolve{};
};
} // namespace Void::Net