diff options
author | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2008-08-08 02:25:47 +0000 |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2008-08-08 02:25:47 +0000 |
commit | 0378f34d85e4fa2d83bae745c44649ccfb9744bb (patch) | |
tree | 57d1f258d7b5bcb798b119f134bdd2cd04f382a7 /plugins/check_http.c | |
parent | 2367f82090e7ff0cc2b0b23590b62f9eb33df528 (diff) | |
download | monitoring-plugins-0378f34d85e4fa2d83bae745c44649ccfb9744bb.tar.gz |
Re-structure the HTTP 1.1 headers to prevent 301s on servers with virtual hosts
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2030 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_http.c')
-rw-r--r-- | plugins/check_http.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c index 07e0079e..f81026f8 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -743,21 +743,23 @@ check_http (void) if (check_cert == TRUE) { result = np_net_ssl_check_cert(days_till_exp); np_net_ssl_cleanup(); - if(sd) close(sd); + if (sd) close(sd); return result; } } #endif /* HAVE_SSL */ - asprintf (&buf, "%s %s HTTP/1.0\r\n%s\r\n", http_method, server_url, user_agent); + /* If a hostname is provided, use HTTP/1.1 and send the hostname before the + * Useragent. This fixes an issue with getting 301 responses from servers + * with virtual hosts */ + if (host_name) + asprintf (&buf, "%s %s HTTP/1.1\r\nHost: %s\r\n%s\r\n", http_method, server_url, host_name, user_agent); + else + asprintf (&buf, "%s %s HTTP/1.0\r\n%s\r\n", http_method, server_url, user_agent); /* tell HTTP/1.1 servers not to keep the connection alive */ asprintf (&buf, "%sConnection: close\r\n", buf); - /* optionally send the host header info */ - if (host_name) - asprintf (&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++) { @@ -835,7 +837,7 @@ check_http (void) #ifdef HAVE_SSL np_net_ssl_cleanup(); #endif - if(sd) close(sd); + if (sd) close(sd); /* reset the alarm */ alarm (0); @@ -1101,13 +1103,13 @@ redir (char *pos, char *status_line) } /* URI_HTTP URI_HOST URI_PORT */ - else if(sscanf (pos, HD3, type, addr, &i) == 3) { + else if (sscanf (pos, HD3, type, addr, &i) == 3) { strcpy (url, HTTP_URL); use_ssl = server_type_check (type); } /* URI_HTTP URI_HOST */ - else if(sscanf (pos, HD4, type, addr) == 2) { + else if (sscanf (pos, HD4, type, addr) == 2) { strcpy (url, HTTP_URL); use_ssl = server_type_check (type); i = server_port_check (use_ssl); |