Skip to content

Commit d69bbce

Browse files
committed
Save curlCode and curlError to lastRequest
redirectCount is supposed to be a long--this was probably causing memory corruption
1 parent eeb00a8 commit d69bbce

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

include/restclient-cpp/connection.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ class Connection {
5656
* @var RequestInfo::redirectCount
5757
* Member 'redirectCount' contains the number of redirects followed. See
5858
* CURLINFO_REDIRECT_COUNT
59+
* @var RequestInfo::curlCode
60+
* Member 'curlCode' contains the cURL code (cast to int). See
61+
* libcurl-errors
62+
* @var RequestInfo::curlError
63+
* Member 'curlError' contains the cURL error as a string, if any. See
64+
* CURLOPT_ERRORBUFFER
5965
*/
6066
typedef struct {
6167
double totalTime;
@@ -65,7 +71,9 @@ class Connection {
6571
double preTransferTime;
6672
double startTransferTime;
6773
double redirectTime;
68-
int redirectCount;
74+
long redirectCount;
75+
int curlCode;
76+
std::string curlError;
6977
} RequestInfo;
7078
/**
7179
* @struct Info
@@ -231,6 +239,7 @@ class Connection {
231239
std::string keyPassword;
232240
std::string uriProxy;
233241
std::string unixSocketPath;
242+
char curlErrorBuf[CURL_ERROR_SIZE];
234243
RestClient::Response performCurlRequest(const std::string& uri);
235244
};
236245
}; // namespace RestClient

source/connection.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ RestClient::Connection::performCurlRequest(const std::string& uri) {
359359
curl_easy_setopt(this->curlHandle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
360360
curl_easy_setopt(this->curlHandle, CURLOPT_USERPWD, authString.c_str());
361361
}
362+
/** set error buffer */
363+
curl_easy_setopt(this->curlHandle, CURLOPT_ERRORBUFFER,
364+
this->curlErrorBuf);
365+
362366
/** set user agent */
363367
curl_easy_setopt(this->curlHandle, CURLOPT_USERAGENT,
364368
this->GetUserAgent().c_str());
@@ -441,6 +445,7 @@ RestClient::Connection::performCurlRequest(const std::string& uri) {
441445
}
442446

443447
res = curl_easy_perform(this->curlHandle);
448+
this->lastRequest.curlCode = res;
444449
if (res != CURLE_OK) {
445450
switch (res) {
446451
case CURLE_OPERATION_TIMEDOUT:
@@ -461,6 +466,8 @@ RestClient::Connection::performCurlRequest(const std::string& uri) {
461466
ret.code = static_cast<int>(http_code);
462467
}
463468

469+
this->lastRequest.curlError = std::string(this->curlErrorBuf);
470+
464471
curl_easy_getinfo(this->curlHandle, CURLINFO_TOTAL_TIME,
465472
&this->lastRequest.totalTime);
466473
curl_easy_getinfo(this->curlHandle, CURLINFO_NAMELOOKUP_TIME,

0 commit comments

Comments
 (0)