
cherokee at cherokee-project
Sep 14, 2009, 8:53 AM
Post #1 of 1
(188 views)
Permalink
|
|
[3662] cherokee/trunk: Implements a new function (cherokee_gethostname) and use it in handler_cgi_base.c when no "Host:" header is present.
|
|
Revision: 3662 http://svn.cherokee-project.com/changeset/3662 Author: aperez Date: 2009-09-14 17:53:16 +0200 (Mon, 14 Sep 2009) Log Message: ----------- Implements a new function (cherokee_gethostname) and use it in handler_cgi_base.c when no "Host:" header is present. Modified Paths: -------------- cherokee/trunk/cherokee/handler_cgi_base.c cherokee/trunk/cherokee/util.c cherokee/trunk/cherokee/util.h cherokee/trunk/configure.in cherokee/trunk/qa/141-FastCGI-EmptyVars.py Modified: cherokee/trunk/cherokee/handler_cgi_base.c =================================================================== --- cherokee/trunk/cherokee/handler_cgi_base.c 2009-09-14 13:25:30 UTC (rev 3661) +++ cherokee/trunk/cherokee/handler_cgi_base.c 2009-09-14 15:53:16 UTC (rev 3662) @@ -297,13 +297,21 @@ cherokee_header_copy_known (&conn->header, header_host, tmp); if (! cherokee_buffer_is_empty(tmp)) { set_env (cgi, "HTTP_HOST", tmp->buf, tmp->len); - + p = strchr (tmp->buf, ':'); if (p != NULL) { set_env (cgi, "SERVER_NAME", tmp->buf, p - tmp->buf); } else { set_env (cgi, "SERVER_NAME", tmp->buf, tmp->len); } + } else { + cherokee_buffer_clean (tmp); + re = cherokee_gethostname (tmp); + if (re == ret_ok) { + set_env (cgi, "SERVER_NAME", tmp->buf, tmp->len); + } else { + LOG_WARNING_S ("Error getting host name.\n"); + } } /* Content-Type Modified: cherokee/trunk/cherokee/util.c =================================================================== --- cherokee/trunk/cherokee/util.c 2009-09-14 13:25:30 UTC (rev 3661) +++ cherokee/trunk/cherokee/util.c 2009-09-14 15:53:16 UTC (rev 3662) @@ -80,6 +80,14 @@ # include <execinfo.h> #endif +#ifdef HAVE_SYS_UTSNAME_H +# include <sys/utsname.h> +#endif + +#ifndef HOST_NAME_MAX +# define HOST_NAME_MAX 255 +#endif + #define ENTRIES "util" const char *cherokee_version = PACKAGE_VERSION; @@ -771,6 +779,40 @@ ret_t +cherokee_gethostname (cherokee_buffer_t *buf) +{ + int re; + +#ifdef HAVE_GETHOSTNAME + char host_name[HOST_NAME_MAX + 1]; + + re = gethostname (host_name, HOST_NAME_MAX); + if (re) { + return ret_error; + } + + cherokee_buffer_add (buf, host_name, strlen(host_name)); + + return ret_ok; + +#elif defined(HAVE_SYS_UTSNAME_H) && defined(HAVE_UNAME) + struct utsname info; + + re = uname (&info); + if (re) { + return ret_error; + } + + cherokee_buffer_add (buf, info.nodename, sizeof(info.nodename)); + + return ret_ok; +#endif + + return ret_error; +} + + +ret_t cherokee_fd_set_nodelay (int fd, cherokee_boolean_t enable) { int re; Modified: cherokee/trunk/cherokee/util.h =================================================================== --- cherokee/trunk/cherokee/util.h 2009-09-14 13:25:30 UTC (rev 3661) +++ cherokee/trunk/cherokee/util.h 2009-09-14 15:53:16 UTC (rev 3662) @@ -144,6 +144,7 @@ */ int cherokee_readdir (DIR *dirstream, struct dirent *entry, struct dirent **result); ret_t cherokee_gethostbyname (const char *hostname, void *addr); +ret_t cherokee_gethostname (cherokee_buffer_t *buf); ret_t cherokee_syslog (int priority, cherokee_buffer_t *buf); ret_t cherokee_getpwnam (const char *name, struct passwd *pwbuf, char *buf, size_t buflen); ret_t cherokee_getgrnam (const char *name, struct group *pwbuf, char *buf, size_t buflen); Modified: cherokee/trunk/configure.in =================================================================== --- cherokee/trunk/configure.in 2009-09-14 13:25:30 UTC (rev 3661) +++ cherokee/trunk/configure.in 2009-09-14 15:53:16 UTC (rev 3662) @@ -457,6 +457,9 @@ AC_SEARCH_LIBS(gethostbyname, [socket nsl resolv]) AC_CHECK_FUNCS(gethostbyname gethostbyname_r) +AC_CHECK_HEADER(sys/utsname.h) +AC_CHECK_FUNCS(gethostname uname) + dnl dnl Check for inet_addr dnl Modified: cherokee/trunk/qa/141-FastCGI-EmptyVars.py =================================================================== --- cherokee/trunk/qa/141-FastCGI-EmptyVars.py 2009-09-14 13:25:30 UTC (rev 3661) +++ cherokee/trunk/qa/141-FastCGI-EmptyVars.py 2009-09-14 15:53:16 UTC (rev 3662) @@ -41,8 +41,7 @@ TestBase.__init__ (self, __file__) self.name = "FastCGI: Variables" - self.request = "GET %s HTTP/1.0\r\n" %(DIR) +\ - "Host: localhost\r\n" + self.request = "GET %s HTTP/1.0\r\n" % (DIR) self.expected_error = 200 self.expected_content = ['PATH_INFO:', 'QUERY_STRING:'] self.forbidden_content = ['from fcgi', 'start_response']
|