Skip to content

Instantly share code, notes, and snippets.

@emag
Last active December 20, 2015 02:09
Show Gist options
  • Save emag/6054353 to your computer and use it in GitHub Desktop.
Save emag/6054353 to your computer and use it in GitHub Desktop.
This is a Byteman rule to get real IP from request via proxy(such as load balancer, reverce proxy). Simply replacing HttpServletRequest#getRemoteAddr return value with HTTP Header: x-forwarded-for value. I tested it on WildFly 8.0.0.Alpha3, JBoss AS 7.1, Tomcat 7.
RULE x-forwarded-for
INTERFACE javax.servlet.http.HttpServletRequest
METHOD getRemoteAddr
AT EXIT
IF $0.getHeader("x-forwarded-for") != null
DO
RETURN $0.getHeader("x-forwarded-for")
ENDRULE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment