sunlabs.brazil.handler
Class VirtualHostHandler
public
class
VirtualHostHandler
extends Object
implements Handler
Handler for managing virtual hosts using the same server configuration.
This prefixes the host name (from the http "host" header, with the
port portion removed) onto the
url and passes the request along.
If no host is provided, the host "default" is used instead.
If hosts require their own server configurations,
use the
MultiHostHandler instead.
Configuration parameters:
- maproot
- If set upon server startup, this handler changes the "root" property
instead of the "url" property, by appending the "host" onto the
document root, instead of prepending the "host" to the url.
- [prefix].[host].
- If the "mapping" property exists that matches the incoming
"host" name, then
that value is used instead of [host] to rewrite the "url" or "root".
- default
- If set, then all hosts for which no mappings are defined are mapped
to the value of this property.
- levels
- If defined, then for the purpose of host matching, only "levels"
of hostnames are considered. If levels=3, then for host:
a.b.c.d.e, the host is considered to be "c.d.e". This enables
support for wildcard-host matching within a virtual domain.
- addlevel=true|false
- If "true", "levels" is specified, and the number of tokens (levels)
in the hostname exceeds "levels", then all the extra tokens in the
hostname are prepended to the URL as initial directories: If
"levels" is 3, and "addlevel=true" then:
host
http://a.b.c.d.e/foo.html
will be mapped to
http://c.d.e/b/a/foo.html
, and the file "foo.html"
should be at [docroot]/c.d.e/b/a/foo.html].
If "addlevel=false", then http://a.b.c.d.e/foo.html
will be mapped to http://c.d.e/foo.html
, and the file
"foo.html" should be at [docroot]/c.d.e/foo.html. In this case,
the "a.b" part of the host is available as part of the host property,
which retains its original value.
With no configuration options, each virtual host document root is in
a subdirectory whose name matches the host (e.g. www.foo.com). The
"maproot" property changes how virtual roots are
distingished: by URL or by document root. The "mapping" properties are
used to choose a name for the subdirectory that differs from the
virtual hostname. Finally, if "default" is set, then virtual hosts
with no subdirectory are all shunted into the subdirectory specified.
Version: 2.1, 02/10/01
Author: Stephen Uhler
public boolean init(
Server server, String prefix)
public boolean respond(
Request request)
Either look for host header, tack on front of url,
or modify the "root" property