LCOV - code coverage report
Current view: top level - http/client - client_connection.hpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 2 2
Test Date: 2026-04-21 17:49:55 Functions: 100.0 % 2 2

            Line data    Source code
       1              : #ifndef THINGER_HTTP_CLIENT_CONNECTION_HPP
       2              : #define THINGER_HTTP_CLIENT_CONNECTION_HPP
       3              : 
       4              : #include <memory>
       5              : #include <mutex>
       6              : #include <boost/noncopyable.hpp>
       7              : 
       8              : #include "../common/http_request.hpp"
       9              : #include "../common/http_response.hpp"
      10              : #include "response_factory.hpp"
      11              : #include "stream_types.hpp"
      12              : #include "../../asio/sockets/tcp_socket.hpp"
      13              : #include "../../asio/sockets/unix_socket.hpp"
      14              : #include "../../util/types.hpp"
      15              : 
      16              : namespace thinger::http {
      17              : 
      18              : class client_connection : public std::enable_shared_from_this<client_connection>, public boost::noncopyable {
      19              : 
      20              :     static constexpr unsigned MAX_BUFFER_SIZE = 4096;
      21              :     static constexpr unsigned MAX_RETRIES = 3;
      22              :     static constexpr auto DEFAULT_TIMEOUT = std::chrono::seconds{60};
      23              :     static constexpr auto CONNECT_TIMEOUT = std::chrono::seconds{10};
      24              : 
      25              : public:
      26              :     static std::atomic<unsigned long> connections;
      27              : 
      28              :     // Constructors
      29              :     explicit client_connection(std::shared_ptr<thinger::asio::socket> socket,
      30              :                                std::chrono::seconds timeout = DEFAULT_TIMEOUT);
      31              : 
      32              :     client_connection(std::shared_ptr<thinger::asio::unix_socket> socket,
      33              :                       const std::string& path,
      34              :                       std::chrono::seconds timeout = DEFAULT_TIMEOUT);
      35              : 
      36              :     virtual ~client_connection();
      37              : 
      38              :     // Main operation - send request and get response
      39              :     awaitable<std::shared_ptr<http_response>> send_request(std::shared_ptr<http_request> request);
      40              : 
      41              :     // Streaming operation - send request and stream response through callback
      42              :     awaitable<stream_result> send_request_streaming(
      43              :         std::shared_ptr<http_request> request,
      44              :         stream_callback callback);
      45              : 
      46              :     // Connection management
      47              :     void close();
      48              :     std::shared_ptr<thinger::asio::socket> release_socket();
      49              :     std::shared_ptr<thinger::asio::socket> get_socket() const { return socket_; }
      50          277 :     bool is_open() const { return socket_ && socket_->is_open(); }
      51              : 
      52              :     // Forward max response size to the underlying parser.
      53          940 :     void set_max_content_size(size_t size) { response_parser_.set_max_content_size(size); }
      54              : 
      55              : private:
      56              :     // Internal helpers
      57              :     awaitable<void> ensure_connected(const http_request& request);
      58              :     awaitable<std::shared_ptr<http_response>> read_response(bool head_request);
      59              : 
      60              :     std::shared_ptr<thinger::asio::socket> socket_;
      61              :     std::string socket_path_;
      62              :     std::chrono::seconds timeout_;
      63              :     uint8_t buffer_[MAX_BUFFER_SIZE];
      64              :     response_factory response_parser_;
      65              :     std::mutex connection_mutex_;
      66              : };
      67              : 
      68              : }
      69              : 
      70              : #endif
        

Generated by: LCOV version 2.0-1