X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fwrite_http.c;h=ec3a01ce228aeb7798a611333b90fdb9d2b4630d;hp=361c39e4d240bb807158aefa68987183ccddf78d;hb=daebbbee0ac53d39a0486aeb8c41fd358f46ed82;hpb=a82395b57384541152423862bcf44c0db7789641 diff --git a/src/write_http.c b/src/write_http.c index 361c39e4..ec3a01ce 100644 --- a/src/write_http.c +++ b/src/write_http.c @@ -69,6 +69,7 @@ struct wh_callback_s int format; CURL *curl; + struct curl_slist *headers; char curl_errbuf[CURL_ERROR_SIZE]; char *send_buffer; @@ -129,8 +130,6 @@ static int wh_send_buffer (wh_callback_t *cb) /* {{{ */ static int wh_callback_init (wh_callback_t *cb) /* {{{ */ { - struct curl_slist *headers; - if (cb->curl != NULL) return (0); @@ -157,14 +156,14 @@ static int wh_callback_init (wh_callback_t *cb) /* {{{ */ curl_easy_setopt (cb->curl, CURLOPT_NOSIGNAL, 1L); curl_easy_setopt (cb->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT); - headers = NULL; - headers = curl_slist_append (headers, "Accept: */*"); + cb->headers = NULL; + cb->headers = curl_slist_append (cb->headers, "Accept: */*"); if (cb->format == WH_FORMAT_JSON) - headers = curl_slist_append (headers, "Content-Type: application/json"); + cb->headers = curl_slist_append (cb->headers, "Content-Type: application/json"); else - headers = curl_slist_append (headers, "Content-Type: text/plain"); - headers = curl_slist_append (headers, "Expect:"); - curl_easy_setopt (cb->curl, CURLOPT_HTTPHEADER, headers); + cb->headers = curl_slist_append (cb->headers, "Content-Type: text/plain"); + cb->headers = curl_slist_append (cb->headers, "Expect:"); + curl_easy_setopt (cb->curl, CURLOPT_HTTPHEADER, cb->headers); curl_easy_setopt (cb->curl, CURLOPT_ERRORBUFFER, cb->curl_errbuf); curl_easy_setopt (cb->curl, CURLOPT_URL, cb->location); @@ -331,6 +330,13 @@ static void wh_callback_free (void *data) /* {{{ */ curl_easy_cleanup (cb->curl); cb->curl = NULL; } + + if (cb->headers != NULL) + { + curl_slist_free_all (cb->headers); + cb->headers = NULL; + } + sfree (cb->name); sfree (cb->location); sfree (cb->user); @@ -557,6 +563,8 @@ static int wh_config_node (oconfig_item_t *ci) /* {{{ */ cb->low_speed_limit = 0; cb->timeout = 0; cb->log_http_error = 0; + cb->headers = NULL; + pthread_mutex_init (&cb->send_lock, /* attr = */ NULL);