diff options
author | LAURENT LICOUR <ll@licour.com> | 2014-10-30 14:40:29 +0100 |
---|---|---|
committer | Sven Nierlein <sven@nierlein.de> | 2015-10-02 21:12:58 +0200 |
commit | 44ba1f7064a1bd73e80f7abd3fd9d29c57c8959d (patch) | |
tree | 203187b09d8423c349b3d9de41fdbd05f20f50dc /plugins/check_http.c | |
parent | 0be10c669ec6d0b5338a274e59f1f964ec702edc (diff) | |
download | monitoring-plugins-44ba1f7064a1bd73e80f7abd3fd9d29c57c8959d.tar.gz |
plugins/check_http.c - fix Host header if explicitly set with -k
Diffstat (limited to 'plugins/check_http.c')
-rw-r--r-- | plugins/check_http.c | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c index 2437406f..b73e2d97 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -869,6 +869,7 @@ check_http (void) double elapsed_time_transfer = 0.0; int page_len = 0; int result = STATE_OK; + char *force_host_header = NULL; /* try to connect to the host at the given port number */ gettimeofday (&tv_temp, NULL); @@ -926,26 +927,42 @@ check_http (void) /* tell HTTP/1.1 servers not to keep the connection alive */ xasprintf (&buf, "%sConnection: close\r\n", buf); + /* check if Host header is explicitly set in options */ + if (http_opt_headers_count) { + for (i = 0; i < http_opt_headers_count ; i++) { + if (strcmp(http_opt_headers[i], "Host: ")) { + force_host_header = http_opt_headers[i]; + } + } + } + /* optionally send the host header info */ if (host_name) { - /* - * Specify the port only if we're using a non-default port (see RFC 2616, - * 14.23). Some server applications/configurations cause trouble if the - * (default) port is explicitly specified in the "Host:" header line. - */ - if ((use_ssl == FALSE && server_port == HTTP_PORT) || - (use_ssl == TRUE && server_port == HTTPS_PORT) || - ( server_address != NULL && strcmp(http_method, "CONNECT") == 0 + if (force_host_header) { + xasprintf (&buf, "%s%s\r\n", buf, force_host_header); + } + else { + /* + * Specify the port only if we're using a non-default port (see RFC 2616, + * 14.23). Some server applications/configurations cause trouble if the + * (default) port is explicitly specified in the "Host:" header line. + */ + if ((use_ssl == FALSE && server_port == HTTP_PORT) || + (use_ssl == TRUE && server_port == HTTPS_PORT) || + (server_address != NULL && strcmp(http_method, "CONNECT") == 0 && host_name != NULL && use_ssl == TRUE)) - xasprintf (&buf, "%sHost: %s\r\n", buf, host_name); - else - xasprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, server_port); + xasprintf (&buf, "%sHost: %s\r\n", buf, host_name); + else + xasprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, server_port); + } } /* optionally send any other header tag */ if (http_opt_headers_count) { for (i = 0; i < http_opt_headers_count ; i++) { - xasprintf (&buf, "%s%s\r\n", buf, http_opt_headers[i]); + if (force_host_header != http_opt_headers[i]) { + xasprintf (&buf, "%s%s\r\n", buf, http_opt_headers[i]); + } } /* This cannot be free'd here because a redirection will then try to access this and segfault */ /* Covered in a testcase in tests/check_http.t */ |