diff options
author | LAURENT LICOUR <ll@licour.com> | 2014-10-30 13:40:29 (GMT) |
---|---|---|
committer | Sven Nierlein <sven@nierlein.de> | 2015-10-02 19:12:58 (GMT) |
commit | 44ba1f7064a1bd73e80f7abd3fd9d29c57c8959d (patch) | |
tree | 203187b09d8423c349b3d9de41fdbd05f20f50dc | |
parent | 0be10c669ec6d0b5338a274e59f1f964ec702edc (diff) | |
download | monitoring-plugins-44ba1f7064a1bd73e80f7abd3fd9d29c57c8959d.tar.gz |
plugins/check_http.c - fix Host header if explicitly set with -k
-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 2437406..b73e2d9 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -869,6 +869,7 @@ check_http (void) | |||
869 | double elapsed_time_transfer = 0.0; | 869 | double elapsed_time_transfer = 0.0; |
870 | int page_len = 0; | 870 | int page_len = 0; |
871 | int result = STATE_OK; | 871 | int result = STATE_OK; |
872 | char *force_host_header = NULL; | ||
872 | 873 | ||
873 | /* try to connect to the host at the given port number */ | 874 | /* try to connect to the host at the given port number */ |
874 | gettimeofday (&tv_temp, NULL); | 875 | gettimeofday (&tv_temp, NULL); |
@@ -926,26 +927,42 @@ check_http (void) | |||
926 | /* tell HTTP/1.1 servers not to keep the connection alive */ | 927 | /* tell HTTP/1.1 servers not to keep the connection alive */ |
927 | xasprintf (&buf, "%sConnection: close\r\n", buf); | 928 | xasprintf (&buf, "%sConnection: close\r\n", buf); |
928 | 929 | ||
930 | /* check if Host header is explicitly set in options */ | ||
931 | if (http_opt_headers_count) { | ||
932 | for (i = 0; i < http_opt_headers_count ; i++) { | ||
933 | if (strcmp(http_opt_headers[i], "Host: ")) { | ||
934 | force_host_header = http_opt_headers[i]; | ||
935 | } | ||
936 | } | ||
937 | } | ||
938 | |||
929 | /* optionally send the host header info */ | 939 | /* optionally send the host header info */ |
930 | if (host_name) { | 940 | if (host_name) { |
931 | /* | 941 | if (force_host_header) { |
932 | * Specify the port only if we're using a non-default port (see RFC 2616, | 942 | xasprintf (&buf, "%s%s\r\n", buf, force_host_header); |
933 | * 14.23). Some server applications/configurations cause trouble if the | 943 | } |
934 | * (default) port is explicitly specified in the "Host:" header line. | 944 | else { |
935 | */ | 945 | /* |
936 | if ((use_ssl == FALSE && server_port == HTTP_PORT) || | 946 | * Specify the port only if we're using a non-default port (see RFC 2616, |
937 | (use_ssl == TRUE && server_port == HTTPS_PORT) || | 947 | * 14.23). Some server applications/configurations cause trouble if the |
938 | ( server_address != NULL && strcmp(http_method, "CONNECT") == 0 | 948 | * (default) port is explicitly specified in the "Host:" header line. |
949 | */ | ||
950 | if ((use_ssl == FALSE && server_port == HTTP_PORT) || | ||
951 | (use_ssl == TRUE && server_port == HTTPS_PORT) || | ||
952 | (server_address != NULL && strcmp(http_method, "CONNECT") == 0 | ||
939 | && host_name != NULL && use_ssl == TRUE)) | 953 | && host_name != NULL && use_ssl == TRUE)) |
940 | xasprintf (&buf, "%sHost: %s\r\n", buf, host_name); | 954 | xasprintf (&buf, "%sHost: %s\r\n", buf, host_name); |
941 | else | 955 | else |
942 | xasprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, server_port); | 956 | xasprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, server_port); |
957 | } | ||
943 | } | 958 | } |
944 | 959 | ||
945 | /* optionally send any other header tag */ | 960 | /* optionally send any other header tag */ |
946 | if (http_opt_headers_count) { | 961 | if (http_opt_headers_count) { |
947 | for (i = 0; i < http_opt_headers_count ; i++) { | 962 | for (i = 0; i < http_opt_headers_count ; i++) { |
948 | xasprintf (&buf, "%s%s\r\n", buf, http_opt_headers[i]); | 963 | if (force_host_header != http_opt_headers[i]) { |
964 | xasprintf (&buf, "%s%s\r\n", buf, http_opt_headers[i]); | ||
965 | } | ||
949 | } | 966 | } |
950 | /* This cannot be free'd here because a redirection will then try to access this and segfault */ | 967 | /* This cannot be free'd here because a redirection will then try to access this and segfault */ |
951 | /* Covered in a testcase in tests/check_http.t */ | 968 | /* Covered in a testcase in tests/check_http.t */ |