Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http: Add verbose option to http() destination #1526

Merged
merged 1 commit into from
Sep 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions modules/http/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,48 @@ _get_body(HTTPDestinationDriver *self, LogMessage *msg)
return log_msg_get_value(msg, LM_V_MESSAGE, NULL);
}

static
void _http_trace_sanitize_dump(const gchar *text, gchar *data, size_t size)
{
gchar *sanitized = g_new0(gchar, size+1);
int i;
for (i = 0; i < size && data[i]; i++)
{
sanitized[i] = g_ascii_isprint(data[i]) ? data[i] : '.';
}
sanitized[i] = 0;
msg_debug("curl trace log",
evt_tag_str("curl_info_type", text),
evt_tag_str("data", sanitized));
g_free(sanitized);
}

gchar *curl_infotype_to_text[] =
{
"curl_trace_text",
"curl_trace_header_in",
"curl_trace_header_out",
"curl_trace_data_in",
"curl_trace_data_out",
"curl_trace_ssl_data_in",
"curl_trace_ssl_data_out",
};

static
gint _http_trace(CURL *handle, curl_infotype type,
char *data, size_t size,
void *userp)
{
if (!G_UNLIKELY(debug_flag))
return 0;

g_assert(type < sizeof(curl_infotype_to_text)/sizeof(curl_infotype_to_text[0]));

_http_trace_sanitize_dump(curl_infotype_to_text[type], data, size);

return 0;
}

static void
_set_curl_opt(HTTPDestinationDriver *self)
{
Expand Down Expand Up @@ -175,6 +217,9 @@ _set_curl_opt(HTTPDestinationDriver *self)
curl_easy_setopt(self->curl, CURLOPT_SSL_VERIFYHOST, self->peer_verify ? 2L : 0L);
curl_easy_setopt(self->curl, CURLOPT_SSL_VERIFYPEER, self->peer_verify ? 1L : 0L);

curl_easy_setopt(self->curl, CURLOPT_DEBUGFUNCTION, _http_trace);
curl_easy_setopt(self->curl, CURLOPT_VERBOSE, 1L);

curl_easy_setopt(self->curl, CURLOPT_TIMEOUT, self->timeout);

if (self->method_type == METHOD_TYPE_PUT)
Expand Down