I would like to know the source IP address from which the request for my resource came. I have the following two methods for getting it.
String ipAddress = (Series) Request.getCurrent().getAttributes().
get("org.restlet.http.headers").getFirstValue("X-Forwarded-For");
String ip = ipAddress.split(" ")[0];
and
List<String> ipsList = Request.getCurrent().getClientInfo().getForwardedAddresses();
String ip = ipsList.get(ipsList.size() - 1);
Two questions:
- Are they correct (does it work)?
- better (if they work, which is better in terms of efficiency / resources / runtime)?
source
share