2727#include < nlohmann/json.hpp>
2828
2929#include " iceberg/catalog/rest/config.h"
30+ #include " iceberg/catalog/rest/http_response.h"
3031#include " iceberg/catalog/rest/iceberg_rest_export.h"
3132#include " iceberg/result.h"
3233
3637namespace iceberg ::rest {
3738
3839// / \brief HTTP client for making requests to Iceberg REST Catalog API.
39- // /
40- // / This class wraps the CPR library and provides a type-safe interface for making
41- // / HTTP requests. It handles authentication, headers, and response parsing.
4240class ICEBERG_REST_EXPORT HttpClient {
4341 public:
44- // / \brief Factory function to create and initialize an HttpClient.
45- // / This is the preferred way to construct an HttpClient, as it can handle
46- // / potential errors during configuration parsing (e.g., invalid headers).
47- // / \param config The catalog configuration.
48- // / \return A Result containing a unique_ptr to the HttpClient, or an Error.
49- static Result<std::unique_ptr<HttpClient>> Make (const RestCatalogConfig& config);
42+ explicit HttpClient (const RestCatalogConfig&);
5043
5144 HttpClient (const HttpClient&) = delete ;
5245 HttpClient& operator =(const HttpClient&) = delete ;
@@ -55,36 +48,42 @@ class ICEBERG_REST_EXPORT HttpClient {
5548
5649 // / \brief Sends a GET request.
5750 // / \param target The target path relative to the base URL (e.g., "/v1/namespaces").
58- Result<cpr::Response > Get (const std::string& target, const cpr::Parameters& params = {},
59- const cpr::Header& headers = {});
51+ Result<HttpResponse > Get (const std::string& target, const cpr::Parameters& params = {},
52+ const cpr::Header& headers = {});
6053
6154 // / \brief Sends a POST request.
6255 // / \param target The target path relative to the base URL (e.g., "/v1/namespaces").
63- Result<cpr::Response > Post (const std::string& target, const cpr::Body& body,
64- const cpr::Parameters& params = {},
65- const cpr::Header& headers = {});
56+ Result<HttpResponse > Post (const std::string& target, const cpr::Body& body,
57+ const cpr::Parameters& params = {},
58+ const cpr::Header& headers = {});
6659
6760 // / \brief Sends a HEAD request.
6861 // / \param target The target path relative to the base URL (e.g., "/v1/namespaces").
69- Result<cpr::Response> Head (const std::string& target,
70- const cpr::Parameters& params = {},
71- const cpr::Header& headers = {});
62+ Result<HttpResponse> Head (const std::string& target, const cpr::Parameters& params = {},
63+ const cpr::Header& headers = {});
7264
7365 // / \brief Sends a DELETE request.
7466 // / \param target The target path relative to the base URL (e.g., "/v
75- Result<cpr::Response > Delete (const std::string& target,
76- const cpr::Parameters& params = {},
77- const cpr::Header& headers = {});
67+ Result<HttpResponse > Delete (const std::string& target,
68+ const cpr::Parameters& params = {},
69+ const cpr::Header& headers = {});
7870
7971 private:
80- // / \brief Private constructor. Use the static Create() factory function instead.
81- explicit HttpClient (cpr::Header session_headers);
82-
8372 // / \brief Internal helper to execute a request.
8473 template <typename Func>
85- Result<cpr::Response> Execute (const std::string& target, const cpr::Parameters& params,
86- const cpr::Header& request_headers,
87- Func&& perform_request);
74+ Result<HttpResponse> Execute (const std::string& target, const cpr::Parameters& params,
75+ const cpr::Header& request_headers,
76+ Func&& perform_request) {
77+ cpr::Header combined_headers = default_headers_;
78+ combined_headers.insert (request_headers.begin (), request_headers.end ());
79+
80+ session_->SetUrl (cpr::Url{target});
81+ session_->SetParameters (params);
82+ session_->SetHeader (combined_headers);
83+
84+ cpr::Response response = perform_request (*session_);
85+ return HttpResponse{std::move (response)};
86+ }
8887
8988 cpr::Header default_headers_;
9089 std::unique_ptr<cpr::Session> session_;
0 commit comments