@Test public void getClientAddressWithHttpXForwardedFor() { Mockito.when(request.getHeader(Mockito.eq("HTTP_X_FORWARDED_FOR"))).thenReturn("192.168.1.1"); Assert.assertEquals("192.168.1.1", ApiServlet.getClientAddress(request)); }
static String getClientAddress(final HttpServletRequest request) { for (final String header : s_clientAddressHeaders) { final String ip = getCorrectIPAddress(request.getHeader(header)); if (ip != null) { return ip; } } return request.getRemoteAddr(); }
ApiServlet extends HttpServlet { static String getClientAddress(final HttpServletRequest request) { for (final String header : s_clientAddressHeaders) { final String ip = getCorrectIPAddress(request.getHeader(header)); if (ip != null) { return ip; } } return request.getRemoteAddr(); } }
ApiServlet extends HttpServlet { static String getClientAddress(final HttpServletRequest request) { for (final String header : s_clientAddressHeaders) { final String ip = getCorrectIPAddress(request.getHeader(header)); if (ip != null) { return ip; } } return request.getRemoteAddr(); } ApiServlet(); }
ApiServlet extends HttpServlet { static String getClientAddress(final HttpServletRequest request) { for (final String header : s_clientAddressHeaders) { final String ip = getCorrectIPAddress(request.getHeader(header)); if (ip != null) { return ip; } } return request.getRemoteAddr(); } ApiServlet(); @Override void init(final ServletConfig config); }
ApiServlet extends HttpServlet { static String getClientAddress(final HttpServletRequest request) { for (final String header : s_clientAddressHeaders) { final String ip = getCorrectIPAddress(request.getHeader(header)); if (ip != null) { return ip; } } return request.getRemoteAddr(); } ApiServlet(); @Override void init(final ServletConfig config); static final Logger s_logger; }