1717 * under the License.
1818 */
1919
20+ #include " iceberg/catalog/rest/http_client.h"
21+
2022#include < nlohmann/json.hpp>
2123
2224#include " cpr/body.h"
2325#include " cpr/cprtypes.h"
2426#include " iceberg/catalog/rest/config.h"
25- #include " iceberg/catalog/rest/http_client_interal.h"
2627#include " iceberg/catalog/rest/json_internal.h"
2728#include " iceberg/json_internal.h"
2829#include " iceberg/util/macros.h"
@@ -94,6 +95,8 @@ Result<HttpResponse> HttpClient::Get(
9495 const std::string& path, const std::unordered_map<std::string, std::string>& params,
9596 const std::unordered_map<std::string, std::string>& headers,
9697 const ErrorHandler& error_handler) {
98+ std::lock_guard<std::mutex> lock (session_mutex_);
99+
97100 PrepareSession (path, headers, params);
98101 cpr::Response response = session_->Get ();
99102 ICEBERG_RETURN_UNEXPECTED (HandleFailureResponse (response, error_handler));
@@ -104,6 +107,8 @@ Result<HttpResponse> HttpClient::Post(
104107 const std::string& path, const std::string& body,
105108 const std::unordered_map<std::string, std::string>& headers,
106109 const ErrorHandler& error_handler) {
110+ std::lock_guard<std::mutex> lock (session_mutex_);
111+
107112 PrepareSession (path, headers);
108113 session_->SetBody (cpr::Body{body});
109114 cpr::Response response = session_->Post ();
@@ -116,6 +121,8 @@ Result<HttpResponse> HttpClient::PostForm(
116121 const std::unordered_map<std::string, std::string>& form_data,
117122 const std::unordered_map<std::string, std::string>& headers,
118123 const ErrorHandler& error_handler) {
124+ std::lock_guard<std::mutex> lock (session_mutex_);
125+
119126 PrepareSession (path, headers);
120127 std::vector<cpr::Pair> pair_list;
121128 pair_list.reserve (form_data.size ());
@@ -131,6 +138,8 @@ Result<HttpResponse> HttpClient::PostForm(
131138Result<HttpResponse> HttpClient::Head (
132139 const std::string& path, const std::unordered_map<std::string, std::string>& headers,
133140 const ErrorHandler& error_handler) {
141+ std::lock_guard<std::mutex> lock (session_mutex_);
142+
134143 PrepareSession (path, headers);
135144 cpr::Response response = session_->Head ();
136145 ICEBERG_RETURN_UNEXPECTED (HandleFailureResponse (response, error_handler));
@@ -140,6 +149,8 @@ Result<HttpResponse> HttpClient::Head(
140149Result<HttpResponse> HttpClient::Delete (
141150 const std::string& path, const std::unordered_map<std::string, std::string>& headers,
142151 const ErrorHandler& error_handler) {
152+ std::lock_guard<std::mutex> lock (session_mutex_);
153+
143154 PrepareSession (path, headers);
144155 cpr::Response response = session_->Delete ();
145156 ICEBERG_RETURN_UNEXPECTED (HandleFailureResponse (response, error_handler));
0 commit comments