[PATCH] httpd.c (Add http_host header for CGI)

David Edwards busybox at dpe.lusars.net
Wed Oct 15 00:23:23 UTC 2008


I've written a short patch (attached below) that sets the "http_host" 
environment variable for CGI scripts. I realize it isn't part of the 
official CGI/1.1 spec, but it is a (documented, even) apache-ism that's 
been widely used (even on non-apache servers, like lighttpd) for a number 
of years now.

I request it be considered for inclusion.

-- 
Index: networking/httpd.c
===================================================================
--- networking/httpd.c	(revision 23678)
+++ networking/httpd.c	(working copy)
@@ -256,6 +256,7 @@
  	USE_FEATURE_HTTPD_CGI(char *user_agent;)
  	USE_FEATURE_HTTPD_CGI(char *http_accept;)
  	USE_FEATURE_HTTPD_CGI(char *http_accept_language;)
+	USE_FEATURE_HTTPD_CGI(char *http_host;)

  	off_t file_size;        /* -1 - unknown */
  #if ENABLE_FEATURE_HTTPD_RANGES
@@ -303,6 +304,7 @@
  #define user_agent        (G.user_agent       )
  #define http_accept       (G.http_accept      )
  #define http_accept_language (G.http_accept_language)
+#define http_host         (G.http_host        )
  #define file_size         (G.file_size        )
  #if ENABLE_FEATURE_HTTPD_RANGES
  #define range_start       (G.range_start      )
@@ -1388,6 +1390,8 @@
  		}
  	}
  	setenv1("HTTP_USER_AGENT", user_agent);
+	if (http_host)
+		setenv1("HTTP_HOST", http_host);
  	if (http_accept)
  		setenv1("HTTP_ACCEPT", http_accept);
  	if (http_accept_language)
@@ -2017,6 +2021,8 @@
  				http_accept = xstrdup(skip_whitespace(iobuf + sizeof("Accept:")-1));
  			} else if (STRNCASECMP(iobuf, "Accept-Language:") == 0) {
  				http_accept_language = xstrdup(skip_whitespace(iobuf + sizeof("Accept-Language:")-1));
+			} else if (STRNCASECMP(iobuf, "Host:") == 0) {
+				http_host = xstrdup(skip_whitespace(iobuf + sizeof("Host:")-1));
  			}
  #endif
  #if ENABLE_FEATURE_HTTPD_BASIC_AUTH



More information about the busybox mailing list