forgot to implement PIHTTPClient headers

This commit is contained in:
2024-11-28 13:13:08 +03:00
parent 4f934fef35
commit cae264a77b
2 changed files with 16 additions and 2 deletions

View File

@@ -22,7 +22,8 @@ int debug_callback(CURL * handle, curl_infotype type, char * data, size_t size,
PRIVATE_DEFINITION_START(PIHTTPClient)
CURL * handle = nullptr;
CURL * handle = nullptr;
curl_slist * header_list = nullptr;
PRIVATE_DEFINITION_END(PIHTTPClient)
@@ -46,6 +47,13 @@ bool PIHTTPClient::init() {
url.append('=');
url.append(ait.value().toPercentageEncoding());
}
headers.clear();
auto hit = request.headers().makeIterator();
while (hit.next()) {
headers << hit.key() + ": " + hit.value();
}
for (const auto & h: headers)
PRIVATE->header_list = curl_slist_append(PRIVATE->header_list, h.dataAscii());
curl_easy_setopt(PRIVATE->handle, CURLOPT_WRITEDATA, this);
curl_easy_setopt(PRIVATE->handle, CURLOPT_READDATA, this);
curl_easy_setopt(PRIVATE->handle, CURLOPT_XFERINFODATA, this);
@@ -58,6 +66,7 @@ bool PIHTTPClient::init() {
curl_easy_setopt(PRIVATE->handle, CURLOPT_HEADERFUNCTION, headerFunc);
curl_easy_setopt(PRIVATE->handle, CURLOPT_URL, url.dataUTF8());
curl_easy_setopt(PRIVATE->handle, CURLOPT_CUSTOMREQUEST, PIHTTP::methodName(request.method()));
curl_easy_setopt(PRIVATE->handle, CURLOPT_HTTPHEADER, PRIVATE->header_list);
curl_easy_setopt(PRIVATE->handle, CURLOPT_NOPROGRESS, 0L);
// curl_easy_setopt(PRIVATE->handle, CURLOPT_VERBOSE, 1L);
// curl_easy_setopt(PRIVATE->handle, CURLOPT_ERRORBUFFER, buffer_error.data());
@@ -66,6 +75,7 @@ bool PIHTTPClient::init() {
curl_easy_setopt(PRIVATE->handle, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(PRIVATE->handle, CURLOPT_INFILESIZE_LARGE, static_cast<curl_off_t>(request.body().size()));
}
return true;
}
@@ -91,8 +101,10 @@ void PIHTTPClient::perform() {
}
}
// piCout << last_error;
if (PRIVATE->header_list) curl_slist_free_all(PRIVATE->header_list);
curl_easy_cleanup(PRIVATE->handle);
PRIVATE->handle = nullptr;
PRIVATE->handle = nullptr;
PRIVATE->header_list = nullptr;
}

View File

@@ -3,6 +3,7 @@
#include "pihttptypes.h"
#include "pip_http_client_export.h"
#include "pistringlist.h"
class PIHTTPClientBase {
@@ -50,6 +51,7 @@ private:
PIString url;
PIString last_error;
PIStringList headers;
PIByteArray buffer_out;
PIHTTP::MessageMutable request, reply;
std::atomic_bool is_cancel = {false};