/** * Sets a header. * * @param name * @param value * @return the response */ public Response header(String name, Date value) { checkCommitted(); getHeaderMap().put(name, DateUtils.formatForHttpHeader(value)); return this; }
public void addEtag(RouteContext routeContext, long lastModified) { if (pippoSettings.isProd()) { String maxAge = pippoSettings.getString(PippoConstants.SETTING_HTTP_CACHE_CONTROL, "3600"); if (maxAge.equals("0")) { routeContext.setHeader(HttpConstants.Header.CACHE_CONTROL, "no-cache"); } else { routeContext.setHeader(HttpConstants.Header.CACHE_CONTROL, "max-age=" + maxAge); } } else { routeContext.setHeader(HttpConstants.Header.CACHE_CONTROL, "no-cache"); } // Use etag on demand: String etag = null; boolean useEtag = pippoSettings.getBoolean(PippoConstants.SETTING_HTTP_USE_ETAG, true); if (useEtag) { // ETag right now is only lastModified long. // maybe we change that in the future. etag = "\"" + lastModified + "\""; routeContext.setHeader(HttpConstants.Header.ETAG, etag); } if (isModified(etag, lastModified, routeContext)) { routeContext.setHeader(HttpConstants.Header.LAST_MODIFIED, DateUtils.formatForHttpHeader(lastModified)); } else if (routeContext.isRequestMethod(HttpConstants.Method.GET)) { routeContext.status(HttpConstants.StatusCode.NOT_MODIFIED); } }