Skip to content

Commit

Permalink
Enhancements so that 'debug' can spit out headers without having to a…
Browse files Browse the repository at this point in the history
…lso log data
  • Loading branch information
nkissebe authored and bbockelm committed Oct 21, 2024
1 parent b3125a1 commit cf4b41f
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/HTTPCommands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,27 @@ int debugCallback(CURL *handle, curl_infotype ci, char *data, size_t size,
(void)handle; /* prevent compiler warning */
(void)clientp;

switch (ci) {
case CURLINFO_TEXT:
fputs("== Info: ", stderr);
fwrite(data, size, 1, stderr);
default: /* in case a new one is introduced to shock us */
return 0;

case CURLINFO_HEADER_OUT:
text = "=> Send header";
dump_plain(text, stderr, (unsigned char *)data, size);
break;
}
return 0;
}

int debugAndDumpCallback(CURL *handle, curl_infotype ci, char *data,
size_t size, void *clientp) {
const char *text;
(void)handle; /* prevent compiler warning */
(void)clientp;

switch (ci) {
case CURLINFO_TEXT:
fputs("== Info: ", stderr);
Expand Down Expand Up @@ -187,7 +208,6 @@ int debugCallback(CURL *handle, curl_infotype ci, char *data, size_t size,
break;
}
dump(text, stderr, (unsigned char *)data, size);

return 0;
}

Expand Down Expand Up @@ -451,10 +471,15 @@ bool HTTPRequest::SetupHandle(CURL *curl) {
this->errorMessage = "curl_easy_setopt( CURLOPT_HTTPHEADER ) failed.";
return false;
}
if (m_log.getMsgMask() & LogMask::Dump) {
if (m_log.getMsgMask() & LogMask::Debug) {
rv = curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, debugCallback);
rv = curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
}
if (m_log.getMsgMask() & LogMask::Dump) {
rv =
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, debugAndDumpCallback);
rv = curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
}

return true;
}
Expand Down

0 comments on commit cf4b41f

Please sign in to comment.