@Test public void testFilter_goodValue() throws Exception { testHeaderHostValue("example.com"); verify(filterChain).doFilter(request, response); }
@Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; for (Entry<String, Pattern> entry : validHeaderPatterns.entrySet()) { if (checkForBadHeader(httpRequest.getHeaders(entry.getKey()), entry.getValue())) { log.warn("rejecting request from {} due to invalid header '{}: {}'", request.getRemoteHost(), entry.getKey(), Joiner.on(",").join(Collections.list(httpRequest.getHeaders(entry.getKey())))); httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } } } chain.doFilter(request, response); }
HeaderPatternFilter extends ComponentSupport implements Filter { @Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; for (Entry<String, Pattern> entry : validHeaderPatterns.entrySet()) { if (checkForBadHeader(httpRequest.getHeaders(entry.getKey()), entry.getValue())) { log.warn("rejecting request from {} due to invalid header '{}: {}'", request.getRemoteHost(), entry.getKey(), Joiner.on(",").join(Collections.list(httpRequest.getHeaders(entry.getKey())))); httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } } } chain.doFilter(request, response); } }
HeaderPatternFilter extends ComponentSupport implements Filter { @Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; for (Entry<String, Pattern> entry : validHeaderPatterns.entrySet()) { if (checkForBadHeader(httpRequest.getHeaders(entry.getKey()), entry.getValue())) { log.warn("rejecting request from {} due to invalid header '{}: {}'", request.getRemoteHost(), entry.getKey(), Joiner.on(",").join(Collections.list(httpRequest.getHeaders(entry.getKey())))); httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } } } chain.doFilter(request, response); }  }
HeaderPatternFilter extends ComponentSupport implements Filter { @Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; for (Entry<String, Pattern> entry : validHeaderPatterns.entrySet()) { if (checkForBadHeader(httpRequest.getHeaders(entry.getKey()), entry.getValue())) { log.warn("rejecting request from {} due to invalid header '{}: {}'", request.getRemoteHost(), entry.getKey(), Joiner.on(",").join(Collections.list(httpRequest.getHeaders(entry.getKey())))); httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } } } chain.doFilter(request, response); }  @Override void init(final FilterConfig filterConfig); @Override void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain); @Override void destroy(); }
HeaderPatternFilter extends ComponentSupport implements Filter { @Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; for (Entry<String, Pattern> entry : validHeaderPatterns.entrySet()) { if (checkForBadHeader(httpRequest.getHeaders(entry.getKey()), entry.getValue())) { log.warn("rejecting request from {} due to invalid header '{}: {}'", request.getRemoteHost(), entry.getKey(), Joiner.on(",").join(Collections.list(httpRequest.getHeaders(entry.getKey())))); httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } } } chain.doFilter(request, response); }  @Override void init(final FilterConfig filterConfig); @Override void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain); @Override void destroy();  }