Created
November 11, 2011 22:52
-
-
Save lbernstein/1359574 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public final class HTTPUtils { | |
| private static final String HEADER_X_FORWARDED_FOR = "X-FORWARDED-FOR"; | |
| public static String remoteAddr(HttpServletRequest request) { | |
| String remoteAddr = request.getRemoteAddr(); | |
| String x; | |
| if ((x = request.getHeader(HEADER_X_FORWARDED_FOR)) != null) { | |
| remoteAddr = x; | |
| int idx = remoteAddr.indexOf(','); | |
| if (idx > -1) { | |
| remoteAddr = remoteAddr.substring(0, idx); | |
| } | |
| } | |
| return remoteAddr; | |
| } | |
| } | |
| //Example borrowed from Johann Burkard blog |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment