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 committed Oct 18, 2024
1 parent b590804 commit f9bc294
Showing 1 changed file with 42 additions and 18 deletions.
60 changes: 42 additions & 18 deletions src/HTTPCommands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,26 +168,46 @@ int debugCallback(CURL *handle, curl_infotype ci, char *data, size_t size,

case CURLINFO_HEADER_OUT:
text = "=> Send header";
dump_plain(text, stderr, (unsigned char *)data, size);
break;
case CURLINFO_DATA_OUT:
text = "=> Send data";
break;
case CURLINFO_SSL_DATA_OUT:
text = "=> Send SSL data";
break;
case CURLINFO_HEADER_IN:
text = "<= Recv header";
break;
case CURLINFO_DATA_IN:
text = "<= Recv data";
break;
case CURLINFO_SSL_DATA_IN:
text = "<= Recv SSL data";
dump_plain(text, stderr, (unsigned char *) data, size);
break;
}
dump(text, stderr, (unsigned char *)data, size);
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);
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;
case CURLINFO_DATA_OUT:
text = "=> Send data";
break;
case CURLINFO_SSL_DATA_OUT:
text = "=> Send SSL data";
break;
case CURLINFO_HEADER_IN:
text = "<= Recv header";
break;
case CURLINFO_DATA_IN:
text = "<= Recv data";
break;
case CURLINFO_SSL_DATA_IN:
text = "<= Recv SSL data";
break;
}
dump(text, stderr, (unsigned char *)data, size);
return 0;
}

Expand Down Expand Up @@ -438,10 +458,14 @@ 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 f9bc294

Please sign in to comment.