Source:
public final void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException { if (!(servletRequest instanceof HttpServletRequest) || !(servletResponse instanceof HttpServletResponse)) { filterChain.doFilter(servletRequest, servletResponse); return; } final HttpServletRequest request = (HttpServletRequest) servletRequest; final HttpServletResponse response = (HttpServletResponse) servletResponse; if (!this.accepts(request)) { filterChain.doFilter(request, response); return; } try (BufferedHttpServletResponse capturedResponse = new BufferedHttpServletResponse(response, new StringWriter(), null)) { request.setAttribute(INJECT_INDICATOR_PARAMETER, Boolean.TRUE); log.debug("Executing the rest of the filter chain"); filterChain.doFilter(request, capturedResponse); log.debug("Executing the rest of the filter chain"); final String contents = capturedResponse.getBufferedServletOutput() .getWriteMethod() == ResponseWriteMethod.WRITER ? capturedResponse.getBufferedServletOutput().getBufferedString() : null; if (contents != null && StringUtils.contains(response.getContentType(), "html") && innerFilterAcceptsInjection(request)) { final int bodyIndex = contents.indexOf("</body>"); if (bodyIndex != -1) { capturedResponse.resetBuffer(); final PrintWriter printWriter = response.getWriter(); printWriter.write(contents.substring(0, bodyIndex)); writeEnvironmentIndicator(css, innerHTML, titlePrefix, printWriter); printWriter.write(contents.substring(bodyIndex)); } } else { if (contents != null) { response.setContentLength(contents.length()); final PrintWriter printWriter = response.getWriter(); printWriter.write(contents); } } } }

Target:
public final void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException { if (!(servletRequest instanceof HttpServletRequest) || !(servletResponse instanceof HttpServletResponse)) { filterChain.doFilter(servletRequest, servletResponse); return; } final HttpServletRequest request = (HttpServletRequest) servletRequest; final HttpServletResponse response = (HttpServletResponse) servletResponse; if (!this.accepts(request)) { filterChain.doFilter(request, response); return; } try (BufferedHttpServletResponse capturedResponse = new BufferedHttpServletResponse(response, new StringWriter(), null)) { request.setAttribute(INJECT_INDICATOR_PARAMETER, Boolean.TRUE); log.debug("Executing the rest of the filter chain"); filterChain.doFilter(request, capturedResponse); log.debug("Executing the rest of the filter chain"); final String contents = capturedResponse.getBufferedServletOutput() .getWriteMethod() == ResponseWriteMethod.WRITER ? capturedResponse.getBufferedServletOutput().getBufferedString() : null; if (contents != null && StringUtils.contains(response.getContentType(), "html") && innerFilterAcceptsInjection(request)) { final int bodyIndex = contents.indexOf("</body>"); if (bodyIndex != -1) { capturedResponse.resetBuffer(); final PrintWriter printWriter = response.getWriter(); printWriter.write(contents.substring(0, bodyIndex)); writeEnvironmentIndicator(css, innerHTML, titlePrefix, printWriter); printWriter.write(contents.substring(bodyIndex)); } } else { if (contents != null) { final PrintWriter printWriter = response.getWriter(); printWriter.write(contents); } } } }