Index: modules/jetty/src/main/java/org/mortbay/jetty/AbstractConnector.java
===================================================================
--- modules/jetty/src/main/java/org/mortbay/jetty/AbstractConnector.java	(révision 2758)
+++ modules/jetty/src/main/java/org/mortbay/jetty/AbstractConnector.java	(copie de travail)
@@ -16,10 +16,14 @@
 package org.mortbay.jetty;
 
 import java.io.IOException;
+import java.net.InetAddress;
 import java.net.Socket;
+import java.net.UnknownHostException;
 
 import org.mortbay.component.LifeCycle;
+import org.mortbay.io.Connection;
 import org.mortbay.io.EndPoint;
+import org.mortbay.io.nio.SelectChannelEndPoint;
 import org.mortbay.log.Log;
 import org.mortbay.thread.ThreadPool;
 import org.mortbay.util.ajax.Continuation;
@@ -33,6 +37,7 @@
  * <li>Buffer management</li>
  * <li>Socket configuration</li>
  * <li>Base acceptor thread</li>
+ * <li>Optional reverse proxy headers checking</li>
  * </ul>
  * 
  * @author gregw
@@ -54,6 +59,7 @@
     private int _acceptors=1;
     private int _acceptorPriorityOffset=0;
     private boolean _useDNS;
+    private boolean _checkReverseProxyHeaders;
     private boolean _reuseAddress=true;
     
     protected int _maxIdleTime=200000; 
@@ -360,10 +366,117 @@
     /* ------------------------------------------------------------ */
     public void customize(EndPoint endpoint, Request request)
         throws IOException
-    {      
+    {
+        if (getCheckReverseProxyHeaders())
+        {
+            checkReverseProxyHeaders(endpoint, request);
+        }
     }
-    
+
     /* ------------------------------------------------------------ */
+    protected void checkReverseProxyHeaders(EndPoint endpoint, Request request)
+        throws IOException
+    {
+        HttpConnection httpConnection = null;
+        
+        if (endpoint instanceof SelectChannelEndPoint)
+        {
+            Connection connection = ((SelectChannelEndPoint) endpoint).getConnection();
+            if (connection instanceof HttpConnection)
+            {
+                httpConnection = (HttpConnection) connection;
+            }
+        }
+        
+        if (httpConnection == null)
+        {
+            // Unable to modify headers via HttpFields
+            return;
+        }
+        
+        HttpFields httpFields = httpConnection.getRequestFields();
+        
+        // Retrieving mod_proxy_http headers from the request
+        String hostHeader = httpFields.getStringField("X-Forwarded-Host");
+        String server = httpFields.getStringField("X-Forwarded-Server");
+        String remoteAddr = httpFields.getStringField("X-Forwarded-For");
+        
+        if (hostHeader != null)
+        {
+            // Update host header	
+            httpFields.put(HttpHeaders.HOST_BUFFER, hostHeader);
+            // Parse this header
+            int colonIndex = hostHeader.indexOf(":");
+            if (colonIndex == -1)
+            {
+                // Prefer host name dedicated header
+                if (server != null)
+                {
+                    request.setServerName(server);
+                }
+                else
+                {
+                    request.setServerName(hostHeader);
+                }
+                
+                // TODO handle https protocol
+                request.setServerPort(80);
+            }
+            else
+            {
+                // Prefer host name dedicated header
+                if (server != null)
+                {
+                    request.setServerName(server);
+                }
+                else
+                {
+                    request.setServerName(hostHeader.substring(0, colonIndex));
+                }
+                
+                String serverPort = hostHeader.substring(colonIndex + 1);
+                
+                try
+                {
+                    request.setServerPort(Integer.valueOf(serverPort).intValue());
+                }
+                catch (NumberFormatException e)
+                {
+                    throw new RuntimeException("Unable to compute port from host header: '" + server + "'", e);
+                }
+            }
+        }
+        else if (server != null)
+        {
+            // Use provided server name
+            request.setServerName(server);
+        }
+        
+        if (remoteAddr != null)
+        {
+            request.setRemoteAddr(remoteAddr);
+            if (_useDNS)
+            {
+                InetAddress inetAddress = null;
+                
+                try
+                {
+                    inetAddress = InetAddress.getByName(remoteAddr);
+                }
+                catch (UnknownHostException e)
+                {
+                    Log.ignore(e);
+                }
+                
+                if (inetAddress != null)
+                {
+                    request.setRemoteHost(inetAddress.getHostName());
+                }
+            }
+        }
+    }
+
+    /* ------------------------------------------------------------ */
     public void persist(EndPoint endpoint)
         throws IOException
     {      
@@ -489,6 +602,18 @@
     }
     
     /* ------------------------------------------------------------ */
+    public boolean getCheckReverseProxyHeaders()
+    {
+        return _checkReverseProxyHeaders;
+    }
+    
+    /* ------------------------------------------------------------ */
+    public void setCheckReverseProxyHeaders(boolean check)
+    {
+        _checkReverseProxyHeaders=check;
+    }
+    
+    /* ------------------------------------------------------------ */
     public String toString()
     {
         String name = this.getClass().getName();
Index: modules/jetty/src/main/java/org/mortbay/jetty/Request.java
===================================================================
--- modules/jetty/src/main/java/org/mortbay/jetty/Request.java	(révision 2758)
+++ modules/jetty/src/main/java/org/mortbay/jetty/Request.java	(copie de travail)
@@ -114,6 +114,8 @@
     private String _characterEncoding;
     private String _queryEncoding;
     private String _serverName;
+    private String _remoteAddr;
+    private String _remoteHost;
     private String _method;
     private String _pathInfo;
     private int _port;
@@ -863,6 +865,8 @@
      */
     public String getRemoteAddr()
     {
+        if (_remoteAddr != null)
+            return _remoteAddr;	
         return _endp==null?null:_endp.getRemoteAddr();
     }
 
@@ -873,8 +877,14 @@
     public String getRemoteHost()
     {
         if (_dns)
+        {
+            if (_remoteHost != null)
+            {
+                return _remoteHost;
+            }
             return _endp==null?null:_endp.getRemoteHost();
-        return _endp==null?null:_endp.getRemoteAddr();
+        }
+        return getRemoteAddr();
     }
 
     /* ------------------------------------------------------------ */
@@ -1437,7 +1447,7 @@
     
     /* ------------------------------------------------------------ */
     /**
-     * @param host The host to set.
+     * @param port The port to set.
      */
     public void setServerPort(int port)
     {
@@ -1446,6 +1456,24 @@
     
     /* ------------------------------------------------------------ */
     /**
+     * @param addr The address to set.
+     */
+    public void setRemoteAddr(String addr)
+    {
+        _remoteAddr = addr;
+    }
+    
+    /* ------------------------------------------------------------ */
+    /**
+     * @param host The host to set.
+     */
+    public void setRemoteHost(String host)
+    {
+        _remoteHost = host;
+    }
+    
+    /* ------------------------------------------------------------ */
+    /**
      * @return Returns the uri.
      */
     public HttpURI getUri()

