@Override
  public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
    String path = ((HttpServletRequest) req).getRequestURI().replaceFirst(((HttpServletRequest) req).getContextPath(), "");

    MAX_AGE_BY_PATH.entrySet().stream()
      .filter(m -> path.startsWith(m.getKey()))
      .map(Map.Entry::getValue)
      .findFirst()
      .ifPresent(maxAge -> ((HttpServletResponse) resp).addHeader(CACHE_CONTROL_HEADER, format(MAX_AGE_TEMPLATE, maxAge)));

    chain.doFilter(req, resp);
  }
@Test
  public void max_age_is_set_to_five_minutes_on_css_of_static() throws Exception {
    HttpServletRequest request = newRequest("/static/css/custom.css");

    underTest.doFilter(request, response, chain);

    verify(response).addHeader("Cache-Control", format("max-age=%s", 300));
  }