I need to get the x-forwarded-for header from requests. Since i already have an http filter, i can easily log remote address using HttpServletRequest.getRemoteAddr()
, whereas logging x-forwarded-for would require additional configuration. My question is, will the HttpServletRequest.getRemoteAddr()
return the same address as x-forwarded-for, are x-forwarded-for and remote address the same?
No, HttpServletRequest.getRemoteAddr()
will return the address of the last proxy, or load balancer through which the request was sent. X-Forwarded-For will return the original address, from which the request was first sent, followed with the address of the proxy or the load balancer.