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()#
explicit HttpClient(Options options)#
~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 url into destination, 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_bytes fail 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().

void reset()#

Clear a previous cancel() so the instance can be reused.

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.

struct Options#

Public Members

int m_timeout_seconds = 60#

Give up if the transfer stalls this long. Zero uses the backend default.

bool m_allow_resume = true#

Resume into an existing partial file with a Range request when the destination already exists.

Servers that ignore Range are detected (a 200 where 206 was expected) and the file is restarted.