Dossy wrote:
BUG: [ 812036 ] Server drops connection for unknown virtual hosts
URL:
http://sourceforge.net/tracker/index.php?func=detail&aid=812036&group_id=3152&atid=103152
Reviewing the above bug, there's some discussion I want to raise before
"fixing" it.
It would be simple to add a new config. parameter which declares the
"default" server when no "Host:" header is provided in the HTTP request
for HTTP 1.0 requests. (When no "Host:" header is provided on an HTTP
1.1 request, this should result in an 400 Bad Request, see Bug #787728.)
In Apache you can declare default virtual host and in my oppinion it
more desired feature than returning 400 Bad Request.
However, what's really interesting is the RFE that's snuck into the
bottom of Bug #812036: glob matching of the Host: header. Clearly,
there's an added performance cost involved in glob matching vs. a
straight hash lookup, but I guess if you're already doing software
virtual hosting, performance probably isn't terribly important.
How do people feel about this? Is glob matching wanted enough to incur
that per-request cost -- only if you're configured for software virtual
hosting, of course.
-- Dossy
In my implementation of virtual hosting within one virtual server (which
I've posted to the list some month ago) we decided to allow wildcard
names for vhosts matching host header. First we try to matchhHost header
exactly then we iterate over hash table and do string match. If you
declare exact vhost then you have optimal solution, if you use wildcards
than you have to do the search.
--tkosiak
Here is the code from my proposal. We've also written code to add and to
remove entries from hashtable and also to declare own function
((*host2vserverPtr)(server, host)) which maps host header to vserver
name. I can repost rest of teh code once more.
/*
*----------------------------------------------------------------------
*
* Ns_HostToVServer --
*
* Get vserver name for given host.
*
* Results:
* Dynamically alloced vserver name
* (or server string ptr if there is no match).
* If not equal to server, then it should be freed
* by the caller.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
char *
Ns_HostToVServer(char *server, char *host)
{
char *vserver;
if (host2vserverPtr != NULL) {
vserver = (*host2vserverPtr)(server, host);
} else {
char *canonicHost;
Tcl_HashEntry *entryPtr;
if (host != NULL) {
register char *p = host;
register char *q;
q = canonicHost = ns_malloc(strlen(host)+1);
while (*p != '\0' && *p != ':') {
*q = *p;
++p;
++q;
}
*q = '\0';
} else {
canonicHost = ns_strdup("");
}
Ns_MutexLock(&lock);
entryPtr = Tcl_FindHashEntry(&hostsHash, canonicHost);
if (entryPtr != NULL) {
vserver = (char *) Tcl_GetHashValue(entryPtr);
} else {
Tcl_HashSearch search;
for (entryPtr = Tcl_FirstHashEntry(&hostsHash, &search);
entryPtr != NULL;
entryPtr = Tcl_NextHashEntry(&search)) {
if (Tcl_StringMatch(canonicHost,
Tcl_GetHashKey(&hostsHash, entryPtr))) {
break;
}
}
if (entryPtr != NULL) {
vserver = (char *) Tcl_GetHashValue(entryPtr);
} else {
vserver = server;
}
}
Ns_MutexUnlock(&lock);
ns_free(canonicHost);
}
return vserver;
}
--
AOLserver - http://www.aolserver.com/
To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: field of
your email blank.