X-Forwarded-For support
This commit is contained in:
parent
b57ee2de7e
commit
3533471d27
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue