Split header debugging onto multiple lines for easier reading

This commit is contained in:
Jason Woods 2016-10-22 13:02:37 +01:00
parent 36917f7780
commit 02d7296210

View File

@ -1501,19 +1501,42 @@ int S3fsCurl::CurlDebugFunc(CURL* hcurl, curl_infotype type, char* data, size_t
} }
switch(type){ switch(type){
case CURLINFO_TEXT: case CURLINFO_TEXT:
// Swap tab indentation with spaces so it stays pretty in syslog
int indent;
indent = 0;
while (*data == '\t' && size > 0) {
indent += 4;
size--;
data++;
}
S3FS_PRN_CURL("* %*s%.*s", indent, "", (int)size, data);
break;
case CURLINFO_HEADER_IN: case CURLINFO_HEADER_IN:
case CURLINFO_HEADER_OUT: case CURLINFO_HEADER_OUT:
char* buff; size_t length, remaining;
if(NULL == (buff = reinterpret_cast<char*>(malloc(size + 2 + 1)))){ int newline;
// could not allocation memory char* p;
S3FS_PRN_CRIT("could not allocate memory");
break; // Print each line individually for tidy output
} remaining = size;
buff[size + 2] = '\0'; p = data;
sprintf(buff, "%c ", (CURLINFO_TEXT == type ? '*' : CURLINFO_HEADER_IN == type ? '<' : '>')); do {
memcpy(&buff[2], data, size); char* eol = (char*)memchr(p, '\n', remaining);
S3FS_PRN_CURL("%s", buff); // no blocking newline = 0;
free(buff); if (eol == NULL) {
eol = (char*)memchr(p, '\r', remaining);
} else if (eol > p && *(eol - 1) == '\r') {
newline++;
}
if (eol != NULL) {
newline++;
eol++;
}
length = eol - p;
S3FS_PRN_CURL("%c %.*s", CURLINFO_HEADER_IN == type ? '<' : '>', (int)length - newline, p);
remaining -= length;
p = eol;
} while (p != NULL && remaining > 0);
break; break;
case CURLINFO_DATA_IN: case CURLINFO_DATA_IN:
case CURLINFO_DATA_OUT: case CURLINFO_DATA_OUT: