1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
// SPDX-License-Identifier: BSD-3-Clause // Copyright (c) 2026 Fernando Sahmkow #pragma once #include <cstddef> #include <memory> #include "../interfaces.h" namespace whiteout::utils { /// Basic HTTP handler with two platform backends: /// * Windows — WinHTTP /// * Other — libcurl (linked at build time) /// /// Requests are dispatched asynchronously onto an internal thread pool; /// each worker owns one backend handle and keeps its connection cache warm. /// Thread-safe: multiple threads may call getAsync / getRangeAsync /// concurrently. /// /// @bind methods, extends=whiteout::interfaces::HttpHandler, java_package=whiteout.utils class SimpleHttpHandler : public interfaces::HttpHandler { public: /// Create a handler with @p nThreads I/O worker threads (default: 4). explicit SimpleHttpHandler(size_t nThreads = 4); ~SimpleHttpHandler() override; // Non-copyable, non-movable (PImpl). SimpleHttpHandler(const SimpleHttpHandler&) = delete; SimpleHttpHandler& operator=(const SimpleHttpHandler&) = delete; /// @bind — Reported handler capability flags. u32 capabilities() const noexcept override; /// @bind skip — std::function callback isn't auto-bindable void getAsync(const std::string& url, interfaces::HttpCallback callback) override; /// @bind skip — std::function callback isn't auto-bindable void getRangeAsync(const std::string& url, u64 start, u64 end, interfaces::HttpCallback callback) override; private: struct Impl; std::unique_ptr<Impl> m_impl; }; } // namespace whiteout::utils