MonitoredHttpRequest extends MonitoredRequest { public static String getClientIp(HttpServletRequest request) { String ip = request.getHeader("X-Forwarded-For"); ip = getIpFromHeaderIfNotAlreadySet("X-Real-IP", request, ip); ip = getIpFromHeaderIfNotAlreadySet("Proxy-Client-IP", request, ip); ip = getIpFromHeaderIfNotAlreadySet("WL-Proxy-Client-IP", request, ip); ip = getIpFromHeaderIfNotAlreadySet("HTTP_CLIENT_IP", request, ip); ip = getIpFromHeaderIfNotAlreadySet("HTTP_X_FORWARDED_FOR", request, ip); if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } return getFirstIp(ip); } MonitoredHttpRequest(HttpServletRequest httpServletRequest,
								StatusExposingByteCountingServletResponse responseWrapper,
								FilterChain filterChain, ConfigurationRegistry configuration, ExecutorService userAgentParsingExecutor); @Override Span createSpan(); static String getClientIp(HttpServletRequest request); String getRequestName(); static String getRequestNameByRequest(HttpServletRequest request, ServletPlugin servletPlugin); static String removeSemicolonContent(String requestUri); @Override void execute(); static final String CONNECTION_ID_ATTRIBUTE; static final String WIDGET_ALLOWED_ATTRIBUTE; static final String MONITORED_HTTP_REQUEST_ATTRIBUTE; static final String USER_AGENT_PARSED_FUTURE_ATTRIBUTE; }
@Test public void testGetClientIp() { final MockHttpServletRequest request = new MockHttpServletRequest(); request.setRemoteAddr("10.1.1.3"); request.addHeader("x-forwarded-for", "10.1.1.1, 10.1.1.2, 10.1.1.3"); assertThat(MonitoredHttpRequest.getClientIp(request)).isEqualTo("10.1.1.1"); }