KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mortbay > http > HostSocketListener


1 //========================================================================
2
//$Id: HostSocketListener.java,v 1.1 2004/10/13 22:31:53 gregwilkins Exp $
3
//Copyright 2004 Mort Bay Consulting Pty. Ltd.
4
//------------------------------------------------------------------------
5
//Licensed under the Apache License, Version 2.0 (the "License");
6
//you may not use this file except in compliance with the License.
7
//You may obtain a copy of the License at
8
//http://www.apache.org/licenses/LICENSE-2.0
9
//Unless required by applicable law or agreed to in writing, software
10
//distributed under the License is distributed on an "AS IS" BASIS,
11
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//See the License for the specific language governing permissions and
13
//limitations under the License.
14
//========================================================================
15

16 package org.mortbay.http;
17
18 import java.net.Socket JavaDoc;
19
20 import org.mortbay.util.InetAddrPort;
21
22 /**
23  * Forced Host Listener
24  * this simple listener extention forces the host header to be set to a specific value.
25  * It is useful when deployed behind old apache mod_proxy implementations that
26  * lie about the real host used by the client.
27  *
28  */

29 public class HostSocketListener extends SocketListener
30 {
31     String JavaDoc _host;
32     
33     public HostSocketListener()
34     {
35         super();
36     }
37
38     public HostSocketListener(InetAddrPort address)
39     {
40         super(address);
41     }
42
43     /**
44      * @return Returns the host.
45      */

46     public String JavaDoc getForcedHost()
47     {
48         return _host;
49     }
50     
51     /**
52      * @param host The host to set.
53      */

54     public void setForcedHost(String JavaDoc host)
55     {
56         _host = host;
57     }
58     
59     /*
60      * @see org.mortbay.http.SocketListener#customizeRequest(java.net.Socket, org.mortbay.http.HttpRequest)
61      */

62     protected void customizeRequest(Socket JavaDoc socket, HttpRequest request)
63     {
64         request.setState(HttpMessage.__MSG_EDITABLE);
65         if (_host==null)
66             request.removeField(HttpFields.__Host);
67         else
68             request.setField(HttpFields.__Host, _host);
69         request.setState(HttpMessage.__MSG_RECEIVED);
70         super.customizeRequest(socket, request);
71     }
72 }
73
Popular Tags