SF.net SVN: nagiosplug:[2030] nagiosplug/trunk

[email protected]
Newsgroups gmane.network.nagios.plugins.cvs
Message-ID <[email protected]>
Revision: 2030
          http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=2030&view=rev
Author:   dermoth
Date:     2008-08-08 02:25:47 +0000 (Fri, 08 Aug 2008)

Log Message:
-----------
Re-structure the HTTP 1.1 headers to prevent 301s on servers with virtual hosts

Modified Paths:
--------------
    nagiosplug/trunk/NEWS
    nagiosplug/trunk/THANKS.in
    nagiosplug/trunk/plugins/check_http.c

Modified: nagiosplug/trunk/NEWS
===================================================================
--- nagiosplug/trunk/NEWS	2008-08-08 02:08:08 UTC (rev 2029)
+++ nagiosplug/trunk/NEWS	2008-08-08 02:25:47 UTC (rev 2030)
@@ -9,6 +9,7 @@
 	check_procs now captures stderr in external command and adds to plugin output
 	check_snmp now only prints perfdata for non numeric values (#1867716)
 	check_icmp now supports packet size modification
+	check_http now sends the Host header first to fix 301s on servers with vitrual hosts (Michael Harris).
 
 1.4.12 27th May 2008
 	Added ./check_nt -v INSTANCES to count number of instances (Alessandro Ren)

Modified: nagiosplug/trunk/THANKS.in
===================================================================
--- nagiosplug/trunk/THANKS.in	2008-08-08 02:08:08 UTC (rev 2029)
+++ nagiosplug/trunk/THANKS.in	2008-08-08 02:25:47 UTC (rev 2030)
@@ -236,3 +236,4 @@
 Christian Schneemann
 Rob Windsor
 Hilko Bengen
+Michael Harris

Modified: nagiosplug/trunk/plugins/check_http.c
===================================================================
--- nagiosplug/trunk/plugins/check_http.c	2008-08-08 02:08:08 UTC (rev 2029)
+++ nagiosplug/trunk/plugins/check_http.c	2008-08-08 02:25:47 UTC (rev 2030)
@@ -743,21 +743,23 @@
     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 @@
 #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 @@
     }
 
     /* 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);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.