// Copyright (c) 2026 Juhapekka Piiroinen // All Rights Reserved. // AmoosedWeb project: https://amoosed.com #pragma once #include "AmoosedWeb/Reader.hpp" #include #include #include #include #include namespace amoosed { struct HttpProbeResponse { int status = 0; std::string content_type, cache_control, content_range, etag; std::string content_security_policy, content_type_options; std::vector body; }; // Synchronous WinHTTP adapter. Accepts HTTPS origins, plus loopback HTTP for // development. It does not follow redirects, send cookies or credentials, or // accept a response body beyond the caller's bound. Call from a worker thread; // cancel is checked between blocking WinHTTP calls and bounded reads. class WindowsHttpHost final : public HttpHost { public: explicit WindowsHttpHost(std::string_view origin, std::string& error); bool ready() const noexcept { return ready_; } void cancel() noexcept override { cancelled_.store(true); } // Only call on the serialized worker before binding a new operation. void reset_cancel() noexcept override { cancelled_.store(false); } bool cancelled() const override { return cancelled_.load(); } bool fetch_range(std::string_view relative_path, std::size_t first, std::size_t last, std::size_t max_body, FetchResponse& response, std::string& error) override; bool fetch_suffix(std::string_view relative_path, std::size_t length, std::size_t max_body, FetchResponse& response, std::string& error) override; bool fetch_complete(std::string_view relative_path, std::size_t max_body, FetchResponse& response, std::string& error) override; // Check hosting routes and response headers without weakening the Reader's // stricter 200/206 carrier operations. HEAD never reads a body. bool probe(std::string_view relative_path, bool head, const std::wstring& range, std::size_t max_body, HttpProbeResponse& response, std::string& error); private: bool fetch(std::string_view relative_path, const std::wstring& range, std::size_t max_body, FetchResponse& response, std::string& error); std::wstring host_; std::uint16_t port_ = 0; bool secure_ = false, ready_ = false; std::atomic_bool cancelled_{false}; }; }