Hey everybody,

I have a little patch that's useful to me for adding request headers in the Collectd Curl plugin. I'd like to provide it here in the hopes that it makes it into the main source tree.

Thanks!

--
Dan Thomson<[email protected]>
Sr. Systems Engineer
Astute Hosting

diff -Nur collectd-5.1.0.orig/src/curl.c collectd-5.1.0/src/curl.c
--- collectd-5.1.0.orig/src/curl.c	2012-04-19 14:31:31.869695743 -0700
+++ collectd-5.1.0/src/curl.c	2012-08-29 09:59:47.015648404 -0700
@@ -63,6 +63,7 @@
   int   response_time;
 
   CURL *curl;
+  struct curl_slist *curl_headers;
   char curl_errbuf[CURL_ERROR_SIZE];
   char *buffer;
   size_t buffer_size;
@@ -137,6 +138,10 @@
   if (wp == NULL)
     return;
 
+  if (wp->curl_headers != NULL)
+    curl_slist_free_all(wp->curl_headers); 
+  wp->curl_headers = NULL;
+
   if (wp->curl != NULL)
     curl_easy_cleanup (wp->curl);
   wp->curl = NULL;
@@ -187,6 +192,19 @@
   return (0);
 } /* }}} int cc_config_set_boolean */
 
+static int cc_config_add_header (web_page_t* wp, oconfig_item_t* ci) /* {{{ */
+{
+  if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
+  {
+    WARNING("curl plugin: `%s' needs exactly one string argument.", ci->key);
+    return (-1);
+  }
+
+  wp->curl_headers = curl_slist_append(wp->curl_headers, ci->values[0].value.string); 
+
+  return 0;
+} /* }}} int cc_config_add_header */
+
 static int cc_config_add_match_dstype (int *dstype_ret, /* {{{ */
     oconfig_item_t *ci)
 {
@@ -379,6 +397,9 @@
   curl_easy_setopt (wp->curl, CURLOPT_URL, wp->url);
   curl_easy_setopt (wp->curl, CURLOPT_FOLLOWLOCATION, 1);
 
+  if (wp->curl_headers)
+    curl_easy_setopt (wp->curl, CURLOPT_HTTPHEADER, wp->curl_headers);
+
   if (wp->user != NULL)
   {
     size_t credentials_size;
@@ -465,6 +486,8 @@
     else if (strcasecmp ("Match", child->key) == 0)
       /* Be liberal with failing matches => don't set `status'. */
       cc_config_add_match (page, child);
+    else if (strcasecmp ("Header", child->key) == 0)
+      cc_config_add_header (page, child);
     else
     {
       WARNING ("curl plugin: Option `%s' not allowed here.", child->key);
_______________________________________________
collectd mailing list
[email protected]
http://mailman.verplant.org/listinfo/collectd

Reply via email to