#pragma once // Transport interface. Real network, in-process dispatch, and scripted mocks // all implement this; callers never change when the transport swaps. #include #include #include "clients/body/stream.h" #include "clients/request.h" #include "clients/response.h" #include "clients/task.h" namespace molo::clients { class TransportError : public std::runtime_error { public: explicit TransportError(const std::string& msg, bool connect_phase = false) : std::runtime_error("molo::clients::Transport: " + msg), connect_phase_(connect_phase) {} // True when the failure happened before any request byte was sent, so // even non-idempotent methods may retry. bool connect_phase() const noexcept { return connect_phase_; } private: bool connect_phase_; }; class Transport { public: virtual ~Transport() = default; virtual const char* name() const = 0; virtual Task send(const ClientRequest& request) = 0; // Streamed download. Default implementation buffers through send(). virtual Task send_stream(const ClientRequest& request, body::ChunkSink sink); virtual void close() {} }; } // namespace molo::clients