01: /*
02: * VirtualHostHandler.java
03: *
04: * Brazil project web application Framework,
05: * export version: 1.1
06: * Copyright (c) 1999-2000 Sun Microsystems, Inc.
07: *
08: * Sun Public License Notice
09: *
10: * The contents of this file are subject to the Sun Public License Version
11: * 1.0 (the "License"). You may not use this file except in compliance with
12: * the License. A copy of the License is included as the file "license.terms",
13: * and also available at http://www.sun.com/
14: *
15: * The Original Code is from:
16: * Brazil project web application Framework release 1.1.
17: * The Initial Developer of the Original Code is: suhler.
18: * Portions created by suhler are Copyright (C) Sun Microsystems, Inc.
19: * All Rights Reserved.
20: *
21: * Contributor(s): cstevens, suhler.
22: *
23: * Version: 1.4
24: * Created by suhler on 99/06/28
25: * Last modified by cstevens on 00/04/20 11:50:19
26: */
27:
28: package sunlabs.brazil.handler;
29:
30: import sunlabs.brazil.server.Handler;
31: import sunlabs.brazil.server.Request;
32: import sunlabs.brazil.server.Server;
33: import java.io.IOException;
34:
35: /**
36: * Handler for managing virtual hosts.
37: * This prefixes the host name (from the host:) header onto the
38: * url and passes the request along. It could be more useful, but isn't.
39: * If no host is provided, the host "default" is used instead.
40: *
41: * @author Stephen Uhler
42: * @version 1.4, 00/04/20
43: */
44:
45: public class VirtualHostHandler implements Handler {
46:
47: public boolean init(Server server, String prefix) {
48: server.log(Server.LOG_DIAGNOSTIC, prefix,
49: "Starting virtual host handler");
50: return true;
51: }
52:
53: /**
54: * look for host header, tack on front of url.
55: */
56:
57: public boolean respond(Request request) throws IOException {
58: String host = (String) request.headers.get("Host");
59: if (host == null) {
60: host = "default";
61: }
62: try {
63: host = host.substring(0, host.indexOf(":"));
64: } catch (Exception e) {
65: }
66: request.log(Server.LOG_DIAGNOSTIC, host + " added to url "
67: + request.url);
68: request.url = "/" + host.toLowerCase() + request.url;
69: return false;
70: }
71: }
|