httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexei Kosut <ako...@nueva.pvt.k12.ca.us>
Subject Re: No HOST header solutions?
Date Thu, 30 May 1996 00:41:15 GMT
On Wed, 29 May 1996, Robert S. Thau wrote:

> In any case, old servers could transition to use of the Host: header
> once 1.1 achieves wide enough deployment that 1.0 clients can be blown
> off in the manner that forms-challenged clients are routinely blown
> off now; in calendar terms, I'd expect that to be a little more than a
> year from now, given that Netscape and Microsoft are both doing Host:
> already in their most recent releases

Hmm. Does anyone have any firm figures on exactly what percentage of
browsers are sending Host headers?

> The point RobH raises about virtual hosting is a good one --- perhaps
> we want to use something a little more heavyweight than Alias to get
> this particular job done, so long as non-Host: clients are a serious
> issue... might that best be expressed as another parameter on the
> VirtualHost directive?  Just a thought...

Yep, it could. Here's a patch. It adds a new directive, ServerPath,
which lets you do this (to continue with our example):

<VirtualHost www.apache.org>
ServerName www.apache.org
ServerPath /apache
DocumentRoot /usr/web/apache
</VirtualHost>

Then, therefore http://www.apache.org/apache/ will get you the Apache
pages, regardless of whether or not the client supports Host.

It also adds a ServerRedirect command which would, if you added
"ServerRedirect On" to the above entry, cause a (Host-header included)
request for http://www.apache.org/ (and its member documents) to be
redirected to http://www.apache.org/apache/. This solves the
double-mapping problem, and the relative link problem, since all links
can now be of the longer form, but if your browser sends Host:, you
can still type in all the shorter ones, and advertise them on teevee
or whatever.

Here's the patch. If this is what people want (it seems to be the best
solution thus far), let's see about putting it in the next beta
release (which would be... when?):

Index: http_core.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_core.c,v
retrieving revision 1.12
diff -c -r1.12 http_core.c
*** http_core.c	1996/05/22 17:35:36	1.12
--- http_core.c	1996/05/30 00:39:42
***************
*** 684,689 ****
--- 684,694 ----
      return NULL;
  }
  
+ char *set_sred (cmd_parms *cmd, core_dir_config *d, int arg) {
+     cmd->server->redirect_path = arg;
+     return NULL;
+ }
+ 
  char *set_content_md5 (cmd_parms *cmd, core_dir_config *d, int arg) {
      d->content_md5 = arg;
      return NULL;
***************
*** 815,820 ****
--- 820,830 ----
  { "ServerAlias", set_server_string_slot,
     (void *)XtOffsetOf (server_rec, names), RSRC_CONF, RAW_ARGS,
     "a name or names alternately used to access the server" },
+ { "ServerPath", set_server_string_slot,
+   (void *)XtOffsetOf (server_rec, path), RSRC_CONF, TAKE1,
+   "The pathname the server can be reached at" },
+ { "ServerRedirect", set_sred, NULL, RSRC_CONF, FLAG,
+     "whether or not to redirect non-path ServerPath locations." },
  { "Timeout", set_timeout, NULL, RSRC_CONF, TAKE1, "timeout duration (sec)"},
  { "KeepAliveTimeout", set_keep_alive_timeout, NULL, RSRC_CONF, TAKE1, "Keep-Alive timeout
duration (sec)"},
  { "KeepAlive", set_keep_alive, NULL, RSRC_CONF, TAKE1, "Maximum Keep-Alive requests per
connection (0 to disable)" },
Index: http_protocol.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_protocol.c,v
retrieving revision 1.20
diff -c -r1.20 http_protocol.c
*** http_protocol.c	1996/05/27 21:08:28	1.20
--- http_protocol.c	1996/05/30 00:39:46
***************
*** 368,373 ****
--- 368,382 ----
  	r->uri += r->hostlen;
  	parse_uri(r, r->uri);
        }
+       if (s->path && !strncmp(r->uri, s->path, strlen(s->path))) {
+ 	r->uri += strlen(s->path);
+ 	if (r->uri[0] != '/') /* e.g. http://servername/path */
+ 	  r->slash_path = 1;
+       }
+       else if (s->path && s->redirect_path) {
+ 	r->uri += 1;
+ 	r->slash_path = 1;
+       }
      }
  
      if (!names) continue;
***************
*** 387,392 ****
--- 396,418 ----
    }
  }
  
+ void check_serverpath (request_rec *r) {
+   server_rec *s;
+ 
+   /* This is the other way we know if we've a virtual host, based on
+    * a ServerPath directive. This is somewhat of a hack, but it works...
+    */
+ 
+   for (s = r->server->next; s; s = s->next) {
+     if (s->path && !strncmp(r->uri, s->path, strlen(s->path))) {
+       r->server = r->connection->server = s;
+       r->uri += strlen(s->path);
+       if (r->uri[0] != '/') /* e.g. http://servername/path */
+ 	r->slash_path = 1;
+     }
+   }
+ }
+ 
  request_rec *read_request (conn_rec *conn)
  {
      request_rec *r = (request_rec *)pcalloc (conn->pool, sizeof(request_rec));
***************
*** 427,432 ****
--- 453,460 ----
  
      if (r->hostname || (r->hostname = table_get(r->headers_in, "Host")))
        check_hostalias(r);
+     else
+       check_serverpath(r);
  
      kill_timeout (r);
      conn->keptalive = 0;   /* We now have a request - so no more short timeouts */
Index: http_request.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_request.c,v
retrieving revision 1.7
diff -c -r1.7 http_request.c
*** http_request.c	1996/05/22 17:35:37	1.7
--- http_request.c	1996/05/30 00:39:50
***************
*** 678,683 ****
--- 678,699 ----
  	return;
      }
  
+     /* Annoying that we have to check for this here... but this seems
+      * to be the best place. This peice of code takes care of problems
+      * with ServerPath - if someone requests http://servername/path,
+      * we need to redirect so that relative links work.
+      *
+      * This also deals with the ServerRedirect situation - where we want
+      * to always redirect if the ServerPath isn't found.
+      */
+     if (r->slash_path) {
+       table_set (r->headers_out, "Location", pstrcat(r->pool, "http://",
+ 				r->server->server_hostname, r->server->path,
+ 				"/", r->uri, NULL));
+       die (REDIRECT, r);
+       return;
+     }
+ 
      if (!r->proxyreq)
      {
  	access_status = unescape_url(r->uri);
Index: httpd.h
===================================================================
RCS file: /export/home/cvs/apache/src/httpd.h,v
retrieving revision 1.21
diff -c -r1.21 httpd.h
*** httpd.h	1996/05/27 19:48:38	1.21
--- httpd.h	1996/05/30 00:39:53
***************
*** 317,322 ****
--- 317,323 ----
    char *protocol;		/* Protocol, as given to us, or HTTP/0.9 */
    char *hostname;		/* Host, as set by full URI or Host: */
    int hostlen;			/* Length of http://host:port in full URI */
+   int slash_path;		/* We have a "bad" path, to be redirected */
  
    char *status_line;		/* Status line, if set by script */
    int status;			/* In any case */
***************
*** 461,466 ****
--- 462,470 ----
    int timeout;			/* Timeout, in seconds, before we give up */
    int keep_alive_timeout;	/* Seconds we'll wait for another request */
    int keep_alive;		/* Maximum requests per connection */
+ 
+   char *path;			/* URL path the server is known by */
+   int redirect_path;		/* Redirect to path if we don't get it? */
  
    char *names;			/* Wildcarded names for HostAlias servers */
    char *virthost;		/* The name given in <VirtualHost> */


-- 
________________________________________________________________________
Alexei Kosut <akosut@nueva.pvt.k12.ca.us>      The Apache HTTP Server
URL: http://www.nueva.pvt.k12.ca.us/~akosut/   http://www.apache.org/
 
      "War does not determine who is right, only who is left."


Mime
View raw message