@Override public Date setHeader(String name, Date date) { response.header(name, date); return date; }
/** * Sets a filename header. It's a shortcut for {@code header(HttpConstants.Header.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\"")}. * * @param filename * @return */ public Response filenameHeader(String filename) { if (filename != null && !filename.isEmpty()) { header(HttpConstants.Header.CONTENT_DISPOSITION, "attachment; filename=\"" + filename + "\""); } else { header(HttpConstants.Header.CONTENT_DISPOSITION, "attachment; filename=\"\""); } return this; }
@Override public <T> T setHeader(String name, T value) { response.header(name, value.toString()); return value; }
/** * Sets this response as not cacheable. * * @return the response */ public Response noCache() { checkCommitted(); // no-cache headers for HTTP/1.1 header(HttpConstants.Header.CACHE_CONTROL, "no-store, no-cache, must-revalidate"); // no-cache headers for HTTP/1.1 (IE) header(HttpConstants.Header.CACHE_CONTROL, "post-check=0, pre-check=0"); // no-cache headers for HTTP/1.0 header(HttpConstants.Header.PRAGMA, "no-cache"); // set the expires to past httpServletResponse.setDateHeader("Expires", 0); return this; }
/** * Sets the content type of the response. * * @param contentType * @return the response */ public Response contentType(String contentType) { checkCommitted(); header(HttpConstants.Header.CONTENT_TYPE, contentType); httpServletResponse.setContentType(contentType); return this; }
@Override public void setResponseHeader(String name, String value) { getResponse().header(name, value); }
@Override public void handle(RouteContext context) { final Response response = context.getResponse(); response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_ORIGIN, allowOrigin); if (exposeHeaders != null) { response.header(HttpConstants.Header.ACCESS_CONTROL_EXPOSE_HEADERS, exposeHeaders); } if (maxAge != -1) { response.header(HttpConstants.Header.ACCESS_CONTROL_MAX_AGE, "" + maxAge); } // According to the documentation only if true is what needs to be set // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials#Directives if (allowCredentials) { response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"); } if (allowMethods != null) { response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_METHODS, allowMethods); } if (allowHeaders != null) { response.header(HttpConstants.Header.ACCESS_CONTROL_ALLOW_HEADERS, allowHeaders); } if (context.getRequestMethod().equals("OPTIONS")) { response.accepted(); return; } context.next(); }
/** * A permanent (3XX status code) redirect. * <p>This method commits the response.</p> * * @param location * @param statusCode */ public void redirect(String location, int statusCode) { checkCommitted(); finalizeResponse(); status(statusCode); header(HttpConstants.Header.LOCATION, location); header(HttpConstants.Header.CONNECTION, "close"); try { httpServletResponse.sendError(statusCode); } catch (IOException e) { throw new PippoRuntimeException(e); } }
private void send(Object object, String contentType) { if (StringUtils.isNullOrEmpty(contentType)) { throw new PippoRuntimeException("You must specify a content type!"); } ContentTypeEngine contentTypeEngine = contentTypeEngines.getContentTypeEngine(contentType); if (contentTypeEngine == null) { throw new PippoRuntimeException("You must set a content type engine for '{}'", contentType); } header(HttpConstants.Header.CONTENT_TYPE, contentTypeEngine.getContentType()); send(contentTypeEngine.toString(object)); }
@Override protected void writeObject(Context context, Object result) { try { context.getResponse() .contentType(CONTENT_TYPE) .header(CLASS_NAME, result == null ? NULL : result.getClass().getName()); if (result != null) { GZIPOutputStream zipStream = new GZIPOutputStream(new BufferedOutputStream(context.getResponse().getOutputStream())); ObjectOutputStream replyStream = new ObjectOutputStream(zipStream); replyStream.writeObject(result); zipStream.finish(); replyStream.flush(); } } catch (IOException e) { } } }
protected void writeObject(Context context, Object result) { try { context.getResponse() .contentType(CONTENT_TYPE) .header(CLASS_NAME, result == null ? NULL : result.getClass().getName()); if (result != null) { ObjectOutputStream replyStream = new ObjectOutputStream(context.getResponse().getOutputStream()); replyStream.writeObject(result); replyStream.flush(); } } catch (IOException e) { } } }
@Override protected void writeObject(Context context, Object result) { try { context.getResponse() .contentType(CONTENT_TYPE) .header(CLASS_NAME, result == null ? NULL : result.getClass().getName()); if (result != null) { GZIPOutputStream zipStream = new GZIPOutputStream(new BufferedOutputStream(context.getResponse().getOutputStream())); ObjectOutputStream replyStream = new ObjectOutputStream(zipStream); replyStream.writeObject(result); zipStream.finish(); replyStream.flush(); } } catch (IOException e) { } } }
protected void writeObject(Context context, Object result) { try { context.getResponse() .contentType(CONTENT_TYPE) .header(CLASS_NAME, result == null ? NULL : result.getClass().getName()); if (result != null) { ObjectOutputStream replyStream = new ObjectOutputStream(context.getResponse().getOutputStream()); replyStream.writeObject(result); replyStream.flush(); } } catch (IOException e) { } } }