httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Sutton <p...@ukweb.com>
Subject Re: protocol/610: Multiple virtual hosts over single connection don't work
Date Fri, 23 May 1997 13:13:09 GMT
On Fri, 23 May 1997, Martin Mares wrote:
> If using multiple HTTP/1.1 GET requests on single connection to retrieve
> data from different virtual hosts, the virtual host list is scanned starting
> with the most recently used VH, not with the first one which causes that most VH's
> are ignored.
> >How-To-Repeat:
> GET / HTTP/1.1, Host: first_virtual_host; GET / HTTP/1.1, Host: primary_server_name
> >Fix:
> Set current_conn->server back to the original value after each call to read_request
> from the http_main main loop

Oh no, he's right. check_hostalias and check_serverpath search through the
vhosts starting at the one after the last one used. If they don't find a
match, they then default to using the last used vhost. Result... pages
served from the wrong vhost. This only occurs when the current request is
for a named-based vhost and the previous used vhost was defined later in
the configuration file. 

But his solution doesn't look right. If you reset the current_conf->server
inside the keepalive loop you'll lose the correct server for real virtual
hosts (which set by find_virtual_host before the
read_request/process_request loop). 

Instead you need to search the whole server chain inside
check_{hostalias,serverpath} for a matching vhost. The patch below does
this and fixes the problem. But I'm not happy with it, and hopefully
someone more familiar with the vhosting code can fix it properly. (It
imports a global, doesn't check the main server if it is a named-vhost,
and doesn't reset the vhost in use if no match is found but the previous
request was a named-vhost). 

//pcs

*** /home/paul/remote-cvs/apache/src/http_protocol.c	Thu May 15 19:36:23 1997
--- ./http_protocol.c	Fri May 23 13:48:46 1997
***************
*** 680,685 ****
--- 680,686 ----
    unsigned port = (*hostname) ? atoi(hostname) : 80;
    server_rec *s;
    int l;
+   extern server_rec *server_conf;
  
    if (port && (port != r->server->port))
      return;
***************
*** 691,697 ****
  
    r->hostname = host;
  
!   for (s = r->server->next; s; s = s->next) {
      const char *names;
      server_addr_rec *sar;
  
--- 692,698 ----
  
    r->hostname = host;
  
!   for (s = server_conf->next; s; s = s->next) {
      const char *names;
      server_addr_rec *sar;
  
***************
*** 740,745 ****
--- 741,747 ----
  }
  
  void check_serverpath (request_rec *r) {
+   extern server_rec *server_conf;
    server_rec *s;
  
    /* This is in conjunction with the ServerPath code in
***************
*** 747,753 ****
     * Host-sending request.
     */
  
!   for (s = r->server->next; s; s = s->next) {
      if (s->addrs && s->path && !strncmp(r->uri, s->path, s->pathlen)
&&
  	(s->path[s->pathlen - 1] == '/' ||
  	 r->uri[s->pathlen] == '/' ||
--- 749,755 ----
     * Host-sending request.
     */
  
!   for (s = server_conf->next; s; s = s->next) {
      if (s->addrs && s->path && !strncmp(r->uri, s->path, s->pathlen)
&&
  	(s->path[s->pathlen - 1] == '/' ||
  	 r->uri[s->pathlen] == '/' ||


Mime
View raw message