/** * Sets a header value that will be added to the HTTP response. If the * header had already been set, the new value overwrites the previous one. * * @see VaadinResponse#setHeader(String, String) * * @param name * the name of the header. * @param value * the header value. */ public void setHeader(String name, String value) { response.setHeader(name, value); }
/** * Sets all conceivable headers that might prevent a response from being * stored in any caches. * */ default void setNoCacheHeaders() { // no-store to disallow storing even if cache would be revalidated // must-revalidate to not use stored value even if someone asks for it setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // Also set legacy values in case of old proxies in between setHeader("Pragma", "no-cache"); setHeader("Expires", "0"); }
private static void doSetCacheTime(VaadinResponse response, long milliseconds) { if (milliseconds <= 0) { response.setHeader("Cache-Control", "no-cache"); response.setHeader("Pragma", "no-cache"); response.setDateHeader("Expires", 0); } else { response.setHeader("Cache-Control", "max-age=" + milliseconds / 1000); response.setDateHeader("Expires", System.currentTimeMillis() + milliseconds); // Required to apply caching in some Tomcats response.setHeader("Pragma", "cache"); } }
/** * Commit the JSON response. We can't write immediately to the output stream * as we want to write only a critical notification if something goes wrong * during the response handling. * * @param response * The response to write to * @param json * The JSON to write * @throws IOException * If there was an exception while writing to the output */ public static void commitJsonResponse(VaadinResponse response, String json) throws IOException { response.setContentType(JsonConstants.JSON_CONTENT_TYPE); // Ensure that the browser does not cache UIDL responses. // iOS 6 Safari requires this (#9732) response.setHeader("Cache-Control", "no-cache"); byte[] b = json.getBytes(UTF_8); response.setContentLength(b.length); OutputStream outputStream = response.getOutputStream(); outputStream.write(b); // NOTE GateIn requires the buffers to be flushed to work outputStream.flush(); } }
/** * Handles a heartbeat request for the given session. Reads the GET * parameter named {@link ApplicationConstants#UI_ID_PARAMETER} to identify * the UI. If the UI is found in the session, sets it * {@link UIInternals#getLastHeartbeatTimestamp() heartbeat timestamp} to * the current time. Otherwise, writes a HTTP Not Found error to the * response. */ @Override public boolean synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { UI ui = session.getService().findUI(request); if (ui != null) { ui.getInternals() .setLastHeartbeatTimestamp(System.currentTimeMillis()); // Ensure that the browser does not cache heartbeat responses. // iOS 6 Safari requires this (#10370) response.setHeader("Cache-Control", "no-cache"); // If Content-Type is not set, browsers assume text/html and may // complain about the empty response body (#12182) response.setHeader("Content-Type", "text/plain"); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND, "UI not found"); } return true; }
response.setHeader("Cache-Control", "no-cache, must-revalidate");