Skip to content

Commit e6fd23c

Browse files
committed
Debug log HTTPS request and response data
1 parent ef05120 commit e6fd23c

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/https_client.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static int closesocket_callback(void __attribute__((unused)) *clientp, curl_sock
139139
}
140140

141141
static void https_log_data(enum LogSeverity level, struct https_fetch_ctx *ctx,
142-
char *ptr, size_t size)
142+
const char * prefix, char *ptr, size_t size)
143143
{
144144
const size_t width = 0x10;
145145

@@ -167,7 +167,7 @@ static void https_log_data(enum LogSeverity level, struct https_fetch_ctx *ctx,
167167
}
168168
}
169169

170-
LOG_REQ(level, "%4.4lx: %s%s", (long)i, hex, str);
170+
LOG_REQ(level, "%s%4.4lx: %s%s", prefix, (long)i, hex, str);
171171
}
172172
}
173173

@@ -191,10 +191,8 @@ int https_curl_debug(CURL __attribute__((unused)) * handle, curl_infotype type,
191191
// not dumping DNS packets because of privacy
192192
case CURLINFO_DATA_OUT:
193193
case CURLINFO_DATA_IN:
194-
// uncomment, to dump
195-
/* DLOG_REQ("data %s", type == CURLINFO_DATA_IN ? "IN" : "OUT");
196-
* https_log_data(LOG_DEBUG, ctx, data, size);
197-
* return 0; */
194+
https_log_data(LOG_DEBUG, ctx, (type == CURLINFO_DATA_IN ? "< " : "> "), data, size);
195+
return 0;
198196
// uninformative
199197
case CURLINFO_SSL_DATA_OUT:
200198
case CURLINFO_SSL_DATA_IN:
@@ -206,7 +204,7 @@ int https_curl_debug(CURL __attribute__((unused)) * handle, curl_infotype type,
206204

207205
// for extra debugging purpose
208206
// if (type != CURLINFO_TEXT) {
209-
// https_log_data(LOG_DEBUG, ctx, data, size);
207+
// https_log_data(LOG_DEBUG, ctx, "", data, size);
210208
// }
211209

212210
// process lines one-by one
@@ -217,7 +215,7 @@ int https_curl_debug(CURL __attribute__((unused)) * handle, curl_infotype type,
217215
// skip empty string and curl info Expire
218216
if (start != NULL && (pos - start) > 0 &&
219217
strncmp(start, "Expire", sizeof("Expire") - 1) != 0) {
220-
// https_log_data(LOG_DEBUG, ctx, start, pos - start);
218+
// https_log_data(LOG_DEBUG, ctx, "", start, pos - start);
221219
DLOG_REQ("%s%.*s", prefix, pos - start, start);
222220
start = NULL;
223221
}
@@ -394,7 +392,7 @@ static int https_fetch_ctx_process_response(https_client_t *client,
394392
} else {
395393
WLOG_REQ("curl response code: %d, content length: %zu", long_resp, ctx->buflen);
396394
if (ctx->buflen > 0) {
397-
https_log_data(LOG_WARNING, ctx, ctx->buf, ctx->buflen);
395+
https_log_data(LOG_WARNING, ctx, "", ctx->buf, ctx->buflen);
398396
}
399397
}
400398
}

0 commit comments

Comments
 (0)