Branch: Tag:

2001-07-21

2001-07-21 09:10:02 by Martin Stjernholm <mast@lysator.liu.se>

Implemented RequestID.url_base, which should be used instead of
query("MyWorldLocation") since it handles shared ports and ports with
path prefixes correctly.

Rev: server/base_server/prototypes.pike:1.23
Rev: server/protocols/http.pike:1.321

2:   // Modified by Francesco Chemolli to add throttling capabilities.   // Copyright © 1996 - 2000, Roxen IS.    - constant cvs_version = "$Id: http.pike,v 1.320 2001/07/15 23:59:48 nilsson Exp $"; + constant cvs_version = "$Id: http.pike,v 1.321 2001/07/21 09:10:01 mast Exp $";   // #define REQUEST_DEBUG   #define MAGIC_ERROR   
1886:    misc->site_prefix_path = p;   }    + static string cached_url_base; +  + string url_base() + { +  // Note: Code duplication in base_server/prototypes.pike. +  +  if (!cached_url_base) { +  string tmp; + // werror ("port_obj->default_port: %O\n" + // "port_obj->port: %O\n" + // "port_obj->name: %O\n" + // "port_obj->conf_data[conf]: %O\n" + // "port_obj->ip: %O\n" + // "misc->host: %O\n" + // "misc->site_prefix_path: %O\n" + // "conf->query (\"MyWorldLocation\"): %O\n", + // port_obj->default_port, + // port_obj->port, + // port_obj->name, + // port_obj->conf_data[conf], + // port_obj->ip, + // misc->host, + // misc->site_prefix_path, + // conf->query ("MyWorldLocation")); +  +  // First look at the host header in the request. +  if ((tmp = misc->host)) { +  string default_port = ":" + port_obj->default_port; +  if (has_suffix (tmp, default_port)) +  // Remove redundant port number. +  cached_url_base = port_obj->name + "://" + +  tmp[..sizeof (tmp) - sizeof (default_port) - 1]; +  else +  cached_url_base = port_obj->name + "://" + tmp; +  } +  +  // Then try the hostname in the port setting. +  else if ((tmp = port_obj->conf_data[conf]->hostname) && tmp != "*") { +  cached_url_base = port_obj->name + "://" + tmp; +  if (port_obj->port != port_obj->default_port) +  cached_url_base += ":" + port_obj->port; +  } +  +  // Then try MyWorldLocation. +  else if (sizeof (tmp = conf->query ("MyWorldLocation"))) { +  if (has_suffix (tmp, "/")) +  cached_url_base = tmp[..sizeof (tmp) - 2]; +  else +  cached_url_base = tmp; +  } +  +  // Last fall back to the numeric ip. +  else { +  cached_url_base = port_obj->name + "://" + port_obj->ip; +  if (port_obj->port != port_obj->default_port) +  cached_url_base += ":" + port_obj->port; +  } +  +  if (string p = misc->site_prefix_path) cached_url_base += p; +  cached_url_base += "/"; + // werror ("url_base: %O\n", cached_url_base); +  } +  return cached_url_base; + } +    /* We got some data on a socket.    * =================================================    */