HttpHeadersFilterRequestWrapper extends HttpServletRequestWrapper { @Override public Enumeration<String> getHeaders(String name) { if (shouldFilter(name)) { return EmptyEnumerationOfString.EMPTY_ENUMERATION; } return super.getHeaders(name); } HttpHeadersFilterRequestWrapper(List<String> badHeaders, HttpServletRequest request); @Override String getHeader(String name); @Override Enumeration<String> getHeaders(String name); @Override Enumeration<String> getHeaderNames();  }
@Test public void filtered_x_forwarded_headers_multi_header() { for (String header : BAD_HEADERS) { assertFalse(String.format("Header %s should return empty enumeration.", header), request.getHeaders(header).hasMoreElements()); assertSame( String.format("Header %s should return singleton enumeration .", header), EmptyEnumerationOfString.EMPTY_ENUMERATION, request.getHeaders(header) ); } }
@Test public void non_filtered_x_forwarded_headers_multi_header() { request = new HttpHeadersFilterRequestWrapper(Collections.emptyList(), mock); for (String header : BAD_HEADERS) { assertTrue(String.format("Header %s should return empty enumeration.", header), request.getHeaders(header).hasMoreElements()); assertNotNull( String.format("Header %s should return a value.", header), request.getHeaders(header).nextElement() ); } }