You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2007/12/11 06:06:17 UTC

svn commit: r603144 - /wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java

Author: ivaynberg
Date: Mon Dec 10 21:06:16 2007
New Revision: 603144

URL: http://svn.apache.org/viewvc?rev=603144&view=rev
Log:
WICKET-1204 Use X-Forwarded-For header for getting the IP address of the client in WebClientInfo

Modified:
    wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java

Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java?rev=603144&r1=603143&r2=603144&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java Mon Dec 10 21:06:16 2007
@@ -58,9 +58,9 @@
 	{
 		super();
 		HttpServletRequest httpServletRequest = requestCycle.getWebRequest()
-				.getHttpServletRequest();
+			.getHttpServletRequest();
 		userAgent = httpServletRequest.getHeader("User-Agent");
-		properties.setRemoteAddress(httpServletRequest.getRemoteAddr());
+		properties.setRemoteAddress(getRemoteAddr(requestCycle));
 		init();
 	}
 
@@ -77,8 +77,8 @@
 		super();
 		this.userAgent = userAgent;
 		HttpServletRequest httpServletRequest = requestCycle.getWebRequest()
-				.getHttpServletRequest();
-		properties.setRemoteAddress(httpServletRequest.getRemoteAddr());
+			.getHttpServletRequest();
+		properties.setRemoteAddress(getRemoteAddr(requestCycle));
 		init();
 	}
 
@@ -100,6 +100,32 @@
 	public final String getUserAgent()
 	{
 		return userAgent;
+	}
+
+	/**
+	 * When using ProxyPass, requestCycle().getHttpServletRequest(). getRemoteAddr() returns the IP
+	 * of the machine forwarding the request. In order to maintain the clients ip address, the
+	 * server places it in the <a
+	 * href="http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#x-headers">X-Forwarded-For</a>
+	 * Header.
+	 * 
+	 * @author Ryan Gravener (rgravener)
+	 * 
+	 * @param requestCycle
+	 *            the request cycle
+	 * @return remoteAddr IP address of the client, using the X-Forwarded-For header and defaulting
+	 *         to: getHttpServletRequest().getRemoteAddr()
+	 * 
+	 */
+	protected String getRemoteAddr(WebRequestCycle requestCycle)
+	{
+		HttpServletRequest httpServletReq = requestCycle.getWebRequest().getHttpServletRequest();
+		String remoteAddr = httpServletReq.getHeader("X-Forwarded-For");
+		if (remoteAddr == null)
+		{
+			remoteAddr = httpServletReq.getRemoteAddr();
+		}
+		return remoteAddr;
 	}
 
 	/**