summaryrefslogtreecommitdiffstats
path: root/plugins/check_http.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_http.c')
-rw-r--r--plugins/check_http.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 07e0079..f81026f 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -743,21 +743,23 @@ check_http (void)
743 if (check_cert == TRUE) { 743 if (check_cert == TRUE) {
744 result = np_net_ssl_check_cert(days_till_exp); 744 result = np_net_ssl_check_cert(days_till_exp);
745 np_net_ssl_cleanup(); 745 np_net_ssl_cleanup();
746 if(sd) close(sd); 746 if (sd) close(sd);
747 return result; 747 return result;
748 } 748 }
749 } 749 }
750#endif /* HAVE_SSL */ 750#endif /* HAVE_SSL */
751 751
752 asprintf (&buf, "%s %s HTTP/1.0\r\n%s\r\n", http_method, server_url, user_agent); 752 /* If a hostname is provided, use HTTP/1.1 and send the hostname before the
753 * Useragent. This fixes an issue with getting 301 responses from servers
754 * with virtual hosts */
755 if (host_name)
756 asprintf (&buf, "%s %s HTTP/1.1\r\nHost: %s\r\n%s\r\n", http_method, server_url, host_name, user_agent);
757 else
758 asprintf (&buf, "%s %s HTTP/1.0\r\n%s\r\n", http_method, server_url, user_agent);
753 759
754 /* tell HTTP/1.1 servers not to keep the connection alive */ 760 /* tell HTTP/1.1 servers not to keep the connection alive */
755 asprintf (&buf, "%sConnection: close\r\n", buf); 761 asprintf (&buf, "%sConnection: close\r\n", buf);
756 762
757 /* optionally send the host header info */
758 if (host_name)
759 asprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, server_port);
760
761 /* optionally send any other header tag */ 763 /* optionally send any other header tag */
762 if (http_opt_headers_count) { 764 if (http_opt_headers_count) {
763 for (i = 0; i < http_opt_headers_count ; i++) { 765 for (i = 0; i < http_opt_headers_count ; i++) {
@@ -835,7 +837,7 @@ check_http (void)
835#ifdef HAVE_SSL 837#ifdef HAVE_SSL
836 np_net_ssl_cleanup(); 838 np_net_ssl_cleanup();
837#endif 839#endif
838 if(sd) close(sd); 840 if (sd) close(sd);
839 841
840 /* reset the alarm */ 842 /* reset the alarm */
841 alarm (0); 843 alarm (0);
@@ -1101,13 +1103,13 @@ redir (char *pos, char *status_line)
1101 } 1103 }
1102 1104
1103 /* URI_HTTP URI_HOST URI_PORT */ 1105 /* URI_HTTP URI_HOST URI_PORT */
1104 else if(sscanf (pos, HD3, type, addr, &i) == 3) { 1106 else if (sscanf (pos, HD3, type, addr, &i) == 3) {
1105 strcpy (url, HTTP_URL); 1107 strcpy (url, HTTP_URL);
1106 use_ssl = server_type_check (type); 1108 use_ssl = server_type_check (type);
1107 } 1109 }
1108 1110
1109 /* URI_HTTP URI_HOST */ 1111 /* URI_HTTP URI_HOST */
1110 else if(sscanf (pos, HD4, type, addr) == 2) { 1112 else if (sscanf (pos, HD4, type, addr) == 2) {
1111 strcpy (url, HTTP_URL); 1113 strcpy (url, HTTP_URL);
1112 use_ssl = server_type_check (type); 1114 use_ssl = server_type_check (type);
1113 i = server_port_check (use_ssl); 1115 i = server_port_check (use_ssl);