Class thl::net::HttpClient#
-
class HttpClient#
Minimal HTTPS GET-to-file client.
Deliberately not a general HTTP library. It does the one thing asset delivery needs — fetch a URL into a file, resumably, with progress and cancellation — and leaves everything else out.
Backends are platform-native (NSURLSession, WinHTTP) rather than a vendored TLS stack, so certificate validation uses the OS trust store and there is no CA bundle to ship or rotate. Where no backend exists the calls return HttpStatus::Unsupported instead of failing to link.
Thread-safe for use from one thread at a time per instance; cancel() may be called from any thread.
Public Functions
-
HttpClient()#
-
~HttpClient()#
-
HttpClient(const HttpClient&) = delete#
-
HttpClient &operator=(const HttpClient&) = delete#
-
HttpResult get_to_file(const std::string &url, const std::filesystem::path &destination, const HttpProgressFn &on_progress = {})#
Fetch
urlintodestination, creating parent directories as needed.On success the file holds the complete body. On any failure the file is left as-is so a later call can resume it; callers that want a clean slate delete it themselves. Blocks until finished, cancelled or timed out.
-
HttpResult get_to_string(const std::string &url, std::string &out_body, std::size_t max_bytes = std::size_t{4} * 1024 * 1024)#
Fetch a small resource into memory — manifests, not payloads.
Bodies larger than
max_bytesfail with HttpError rather than allocating.
-
void cancel()#
Ask the in-flight request to stop.
Safe from any thread; a request that has already finished is unaffected. The flag stays set until reset().
-
inline bool cancelled() const#
Public Static Functions
-
static bool supported()#
True when this build has a real backend.
False means every request will return HttpStatus::Unsupported.
-
HttpClient()#