LCOV - code coverage report
Current view: top level - include/hpactor/net - http_client.hpp (source / functions) Coverage Total Hit
Test: HPActor Coverage Lines: 100.0 % 1 1
Test Date: 2026-05-20 02:24:49 Functions: - 0 0
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : // Copyright 2026 HPActor Contributors
       2                 :             : //
       3                 :             : // Licensed under the Apache License, Version 2.0 (the "License");
       4                 :             : // you may not use this file except in compliance with the License.
       5                 :             : // You may obtain a copy of the License at
       6                 :             : //
       7                 :             : //     http://www.apache.org/licenses/LICENSE-2.0
       8                 :             : //
       9                 :             : // Unless required by applicable law or agreed to in writing, software
      10                 :             : // distributed under the License is distributed on an "AS IS" BASIS,
      11                 :             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12                 :             : // See the License for the specific language governing permissions and
      13                 :             : // limitations under the License.
      14                 :             : 
      15                 :             : #pragma once
      16                 :             : 
      17                 :             : #include <hpactor/net/http_connection.hpp>
      18                 :             : #include <hpactor/net/http_types.hpp>
      19                 :             : #include <hpactor/rpc/rpc_channel.hpp>
      20                 :             : #include <hpactor/types/types.hpp>
      21                 :             : 
      22                 :             : #include <chrono>
      23                 :             : #include <memory>
      24                 :             : #include <string>
      25                 :             : #include <vector>
      26                 :             : 
      27                 :             : namespace hpactor {
      28                 :             : namespace net {
      29                 :             : 
      30                 :             : class EventLoop;
      31                 :             : 
      32                 :             : // ---------------------------------------------------------------------------
      33                 :             : // HttpClient — HTTP egress for actor-to-external communication
      34                 :             : // ---------------------------------------------------------------------------
      35                 :             : class HttpClient {
      36                 :             :   public:
      37                 :             :     explicit HttpClient(EventLoop* loop);
      38                 :             :     ~HttpClient();
      39                 :             : 
      40                 :             :     HttpClient(const HttpClient&) = delete;
      41                 :             :     HttpClient& operator=(const HttpClient&) = delete;
      42                 :             : 
      43                 :             :     // Core: async HTTP request with future response
      44                 :             :     RpcFuture<StreamBuffer> request(HttpMethod method,
      45                 :             :                                      const std::string& url,
      46                 :             :                                      std::vector<HttpHeader> headers = {},
      47                 :             :                                      StreamBuffer body = {});
      48                 :             : 
      49                 :             :     // Convenience methods
      50                 :             :     RpcFuture<StreamBuffer> get(const std::string& url,
      51                 :             :                                  std::vector<HttpHeader> headers = {});
      52                 :             :     RpcFuture<StreamBuffer> post(const std::string& url,
      53                 :             :                                   StreamBuffer body,
      54                 :             :                                   std::vector<HttpHeader> headers = {});
      55                 :             :     RpcFuture<StreamBuffer> put(const std::string& url,
      56                 :             :                                  StreamBuffer body,
      57                 :             :                                  std::vector<HttpHeader> headers = {});
      58                 :             :     RpcFuture<StreamBuffer> del(const std::string& url,
      59                 :             :                                  std::vector<HttpHeader> headers = {});
      60                 :             : 
      61                 :             :     // Cancel all in-flight requests
      62                 :             :     void abort();
      63                 :             : 
      64                 :             :     // Configuration
      65                 :             :     void set_default_timeout(std::chrono::milliseconds timeout) {
      66                 :             :         default_timeout_ = timeout;
      67                 :             :     }
      68                 :             :     void set_max_retries(int retries) { max_retries_ = retries; }
      69                 :             : 
      70                 :             :   private:
      71                 :             :     [[maybe_unused]] EventLoop* loop_ = nullptr;
      72                 :           1 :     std::chrono::milliseconds default_timeout_{5000};
      73                 :             :     int max_retries_{3};
      74                 :             : };
      75                 :             : 
      76                 :             : } // namespace net
      77                 :             : } // namespace hpactor
        

Generated by: LCOV version 2.0-1