@@ -126,12 +126,20 @@ long DatabaseAPI::dbGet(const char *a_url_path,
126126 curl_easy_setopt (m_curl, CURLOPT_WRITEDATA, &res_json);
127127 curl_easy_setopt (m_curl, CURLOPT_ERRORBUFFER, error);
128128 curl_easy_setopt (m_curl, CURLOPT_HTTPGET, 1 );
129+ struct curl_slist * headers = nullptr ;
129130
131+ // safe: curl_slist_append copies the string internally
132+ std::string header = " x-correlation-id: " + log_context.correlation_id ;
133+ headers = curl_slist_append (headers, header.c_str ());
134+
135+ // attach headers to the CURL handle
136+ curl_easy_setopt (m_curl, CURLOPT_HTTPHEADER, headers);
130137 CURLcode res = curl_easy_perform (m_curl);
131138
132139 long http_code = 0 ;
133140 curl_easy_getinfo (m_curl, CURLINFO_RESPONSE_CODE, &http_code);
134-
141+ curl_slist_free_all (headers);
142+
135143 if (res == CURLE_OK) {
136144 if (res_json.size ()) {
137145 try {
@@ -168,13 +176,14 @@ bool DatabaseAPI::dbGetRaw(const std::string url, string &a_result) {
168176 a_result.clear ();
169177 error[0 ] = 0 ;
170178
179+ curl_easy_setopt (m_curl, CURLOPT_HTTPHEADER, nullptr ); // Clear any previous headers
180+ // attach headers to the CURL handle
171181 curl_easy_setopt (m_curl, CURLOPT_URL, url.c_str ());
172182 curl_easy_setopt (m_curl, CURLOPT_WRITEDATA, &a_result);
173183 curl_easy_setopt (m_curl, CURLOPT_ERRORBUFFER, error);
174184 curl_easy_setopt (m_curl, CURLOPT_HTTPGET, 1 );
175185
176186 CURLcode res = curl_easy_perform (m_curl);
177-
178187 long http_code = 0 ;
179188 curl_easy_getinfo (m_curl, CURLINFO_RESPONSE_CODE, &http_code);
180189 if (res == CURLE_OK && (http_code >= 200 && http_code < 300 ))
@@ -198,7 +207,14 @@ long DatabaseAPI::dbPost(const char *a_url_path,
198207
199208 // TODO: construct URL outside of function
200209 const string url = buildSearchParamURL (a_url_path, a_params);
210+ struct curl_slist * headers = nullptr ;
211+
212+ // safe: curl_slist_append copies the string internally
213+ std::string header = " x-correlation-id: " + log_context.correlation_id ;
214+ headers = curl_slist_append (headers, header.c_str ());
201215
216+ // attach headers to the CURL handle
217+ curl_easy_setopt (m_curl, CURLOPT_HTTPHEADER, headers);
202218 curl_easy_setopt (m_curl, CURLOPT_URL, url.c_str ());
203219 curl_easy_setopt (m_curl, CURLOPT_WRITEDATA, &res_json);
204220 curl_easy_setopt (m_curl, CURLOPT_ERRORBUFFER, error);
@@ -210,6 +226,7 @@ long DatabaseAPI::dbPost(const char *a_url_path,
210226 a_body ? a_body->c_str () : empty_body);
211227
212228 CURLcode res = curl_easy_perform (m_curl);
229+ curl_slist_free_all (headers);
213230
214231 long http_code = 0 ;
215232 curl_easy_getinfo (m_curl, CURLINFO_RESPONSE_CODE, &http_code);
0 commit comments