X-Forwarded-For support

This commit is contained in:
Andy Janata 2012-09-22 18:43:30 -07:00
parent b57ee2de7e
commit 3533471d27
1 changed files with 10 additions and 8 deletions

View File

@ -58,16 +58,18 @@ public class RequestWrapper {
}
/**
* If there is an {@code X-Forwarded-For} header, the <strong>last</strong> entry in that list
* is returned instead.
* @see HttpServletRequest#getRemoteAddr()
*/
public String getRemoteAddr() {
return request.getRemoteAddr();
}
/**
* @see HttpServletRequest#getRemoteHost()
*/
public String getRemoteHost() {
return request.getRemoteHost();
String addr = request.getHeader("X-Forwarded-For");
if (null != addr) {
final String[] addrs = addr.split(",", -1);
addr = addrs[addrs.length - 1];
} else {
addr = request.getRemoteAddr();
}
return addr;
}
}