HttpHeadersFilterRequestWrapper extends HttpServletRequestWrapper { @Override public String getHeader(String name) { if (shouldFilter(name)) { return null; } return super.getHeader(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 filter_is_case_insensitive() { request = new HttpHeadersFilterRequestWrapper(Collections.singletonList("x-forwarded-host"), mock); assertNull(request.getHeader("X-Forwarded-Host")); assertNotNull(request.getHeader("X-Forwarded-For")); }
@Test public void filtered_x_forwarded_headers_single_header() { for (String header : BAD_HEADERS) { assertNull(String.format("Header %s should be filtered.", header), request.getHeader(header)); } }
@Test public void non_filtered_x_forwarded_headers_single_header() { request = new HttpHeadersFilterRequestWrapper(Collections.emptyList(), mock); for (String header : BAD_HEADERS) { assertNotNull(String.format("Header %s should be present.", header), request.getHeader(header)); } }