HttpServletRequestWrapper extends HttpServerRequest { @Override public boolean parseClientIpAndPort(Span span) { if (parseClientIpFromXForwardedFor(span)) return true; return span.remoteIpAndPort(delegate.getRemoteAddr(), delegate.getRemotePort()); } HttpServletRequestWrapper(HttpServletRequest delegate); static HttpServerRequest create(HttpServletRequest request); @Override final Object unwrap(); @Override boolean parseClientIpAndPort(Span span); @Override final String method(); @Override String route(); @Override final String path(); @Override String url(); @Override final String header(String name);  }
@Test public void parseClientIpAndPort_prefersXForwardedFor() { when(span.remoteIpAndPort("1.2.3.4", 0)).thenReturn(true); when(request.getHeader("X-Forwarded-For")).thenReturn("1.2.3.4"); wrapper.parseClientIpAndPort(span); verify(span).remoteIpAndPort("1.2.3.4", 0); verifyNoMoreInteractions(span); }
@Test public void parseClientIpAndPort_skipsRemotePortOnXForwardedFor() { when(request.getHeader("X-Forwarded-For")).thenReturn("1.2.3.4"); when(span.remoteIpAndPort("1.2.3.4", 0)).thenReturn(true); wrapper.parseClientIpAndPort(span); verify(span).remoteIpAndPort("1.2.3.4", 0); verifyNoMoreInteractions(span); }
@Test public void parseClientIpAndPort_acceptsRemoteAddr() { when(request.getRemoteAddr()).thenReturn("1.2.3.4"); when(request.getRemotePort()).thenReturn(61687); wrapper.parseClientIpAndPort(span); verify(span).remoteIpAndPort("1.2.3.4", 61687); verifyNoMoreInteractions(span); }