/** * This function sets * * Cache-Control: no-cache, no-store * Date: (current date) * Expires: 1970 * * => it therefore effectively forces the browser and every proxy in between * not to cache content. * * See also https://devcenter.heroku.com/articles/increasing-application-performance-with-http-cache-headers * * @return this result for chaining. */ public Result doNotCacheContent() { addHeader(CACHE_CONTROL, CACHE_CONTROL_DEFAULT_NOCACHE_VALUE); addHeader(DATE, DateUtil.formatForHttpHeader(System.currentTimeMillis())); addHeader(EXPIRES, DateUtil.formatForHttpHeader(0L)); return this; }
public static Result created(Optional<String> url) { Result result = status(Result.SC_201_CREATED); if (url.isPresent()) { result.addHeader(Result.LOCATION, url.get()); } return result; }
/** * A redirect that uses 303 see other. * * @param url * The url used as redirect target. * @return A nicely configured result with status code 303 and the url set * as Location header. */ public Result redirect(String url) { status(Result.SC_303_SEE_OTHER); addHeader(Result.LOCATION, url); return this; }
/** * A redirect that uses 307 see other. * * @param url * The url used as redirect target. * @return A nicely configured result with status code 307 and the url set * as Location header. */ public Result redirectTemporary(String url) { status(Result.SC_307_TEMPORARY_REDIRECT); addHeader(Result.LOCATION, url); return this; } /**
public void addEtag(Context context, Result result, Long lastModified) { result.addHeader(HttpHeaderConstants.CACHE_CONTROL, "no-cache"); } else { String maxAge = ninjaProperties.getWithDefault(HTTP_CACHE_CONTROL, result.addHeader(HttpHeaderConstants.CACHE_CONTROL, "no-cache"); } else { result.addHeader(HttpHeaderConstants.CACHE_CONTROL, "max-age=" + maxAge); result.addHeader(HttpHeaderConstants.ETAG, etag); result.addHeader(HttpHeaderConstants.LAST_MODIFIED, DateUtil.formatForHttpHeader(lastModified));
/** * A redirect that uses 303 see other. * * The redirect does NOT need a template and does NOT * render a text in the Http body by default. * * If you wish to do so please * remove the {@link NoHttpBody} that is set as renderable of * the Result. * * @param url * The url used as redirect target. * @return A nicely configured result with status code 303 and the url set * as Location header. Renders no Http body by default. */ public static Result redirect(String url) { Result result = status(Result.SC_303_SEE_OTHER); result.addHeader(Result.LOCATION, url); result.render(Result.NO_HTTP_BODY); return result; }
/** * A redirect that uses 307 see other. * * The redirect does NOT need a template and does NOT * render a text in the Http body by default. * * If you wish to do so please * remove the {@link NoHttpBody} that is set as renderable of * the Result. * * @param url * The url used as redirect target. * @return A nicely configured result with status code 307 and the url set * as Location header. Renders no Http body by default. */ public static Result redirectTemporary(String url) { Result result = status(Result.SC_307_TEMPORARY_REDIRECT); result.addHeader(Result.LOCATION, url); result.render(Result.NO_HTTP_BODY); return result; }
Result result = ninja.getUnauthorizedResult(context).addHeader( Result.WWW_AUTHENTICATE, challenge); return result;
.addHeader(Result.WWW_AUTHENTICATE, "None") .supportedContentTypes(Result.TEXT_HTML, Result.APPLICATION_JSON, Result.APPLICATION_XML) .fallbackContentType(Result.TEXT_HTML)