From f2919408f226280cdf9cab2de81dd1716ec31a93 Mon Sep 17 00:00:00 2001 From: Marc Fournier Date: Tue, 12 Jan 2016 13:48:15 +0100 Subject: [PATCH] apache: warn about possible misconfiguration When the server doesn't return `Content-Type: text-plain`, it's a strong hint that we're not querying the right URL. Fixes #1170 --- src/apache.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/apache.c b/src/apache.c index 13c8db66..ee062206 100644 --- a/src/apache.c +++ b/src/apache.c @@ -596,13 +596,16 @@ static int apache_read_host (user_data_t *user_data) /* {{{ */ st = user_data->data; + int status; + + char *content_type; + static const char *text_plain = "text/plain"; + assert (st->url != NULL); /* (Assured by `config_add') */ if (st->curl == NULL) { - int status; - status = init_host (st); if (status != 0) return (-1); @@ -625,6 +628,16 @@ static int apache_read_host (user_data_t *user_data) /* {{{ */ st->server_type = APACHE; } + status = curl_easy_getinfo (st->curl, CURLINFO_CONTENT_TYPE, &content_type); + if ((status == CURLE_OK) && (content_type != NULL) && + (strncasecmp (content_type, text_plain, strlen (text_plain)) != 0)) + { + WARNING ("apache plugin: `Content-Type' response header is not `%s' " + "(received: `%s'). Expecting unparseable data. Please check `URL' " + "parameter (missing `?auto' suffix ?)", + text_plain, content_type); + } + ptr = st->apache_buffer; saveptr = NULL; while ((line = strtok_r (ptr, "\n\r", &saveptr)) != NULL) -- 2.11.0