public void onBeforeWriteResponseBody(HttpServletRequest request, XHttpServletResponse response) {

        if (!isEligibleToExpirationHeaderGeneration(request, response)) {
            return;
        }

        Date expirationDate = getExpirationDate(request, response);
        if (expirationDate == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Request '{}' with response status '{}' content-type '{}', no expiration configured", new Object[] {
                        request.getRequestURI(), response.getStatus(), response.getContentType() });
            }
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("Request '{}' with response status '{}' content-type '{}', set expiration date {}", new Object[] {
                        request.getRequestURI(), response.getStatus(), response.getContentType(), expirationDate });
            }

            String maxAgeDirective = "max-age=" + ((expirationDate.getTime() - System.currentTimeMillis()) / 1000);

            String cacheControlHeader = response.getCacheControlHeader();
            String newCacheControlHeader = (cacheControlHeader == null) ? maxAgeDirective : cacheControlHeader + ", " + maxAgeDirective;
            response.setHeader(HEADER_CACHE_CONTROL, newCacheControlHeader);
            response.setDateHeader(HEADER_EXPIRES, expirationDate.getTime());
        }

    }