public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) {
            HttpServletRequest httpRequest = (HttpServletRequest) request;
            HttpServletResponse httpResponse = (HttpServletResponse) response;

            if (response.isCommitted()) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Request '" + httpRequest.getRequestURL()
                            + "', can not apply ExpiresFilter on already committed response.");
                }
                chain.doFilter(request, response);
            } else if (active) {
                XHttpServletResponse xResponse = new XHttpServletResponse(httpRequest, httpResponse);
                chain.doFilter(request, xResponse);
                if (!xResponse.isWriteResponseBodyStarted()) {
                    // Empty response, manually trigger
                    // onBeforeWriteResponseBody()
                    onBeforeWriteResponseBody(httpRequest, xResponse);
                }
            } else {
                if (logger.isDebugEnabled()) {
                    logger.debug("Request '" + httpRequest.getRequestURL() + "', ExpiresFilter is NOT active");
                }
                chain.doFilter(request, response);
            }
        } else {
            chain.doFilter(request, response);
        }
    }