/** * Sets a new session for this result, discarding the existing session. * * @param session the session to set with this result * @return the new result */ public Result withSession(Session session) { return new Result(header, body, session, flash, cookies); }
/** * Generates a 307 Temporary Redirect result. * * @param url The url to redirect. * @return the result */ public static Result temporaryRedirect(String url) { return new Result(TEMPORARY_REDIRECT, Collections.singletonMap(LOCATION, url)); }
/** * Generates a 308 Permanent Redirect result. * * @param url The url to redirect. * @return the result */ public static Result permanentRedirect(String url) { return new Result(PERMANENT_REDIRECT, Collections.singletonMap(LOCATION, url)); }
/** * Generates a 303 See Other result. * * @param url The url to redirect. * @return the result */ public static Result redirect(String url) { return new Result(SEE_OTHER, Collections.singletonMap(LOCATION, url)); }
/** * Generates a 301 Moved Permanently result. * * @param url The url to redirect. * @return the result */ public static Result movedPermanently(String url) { return new Result(MOVED_PERMANENTLY, Collections.singletonMap(LOCATION, url)); }
/** * Generates a 303 See Other result. * * @param url The url to redirect. * @return the result */ public static Result redirect(String url) { return new Result(SEE_OTHER, Collections.singletonMap(LOCATION, url)); }
/** * Generates a 301 Moved Permanently result. * * @param url The url to redirect. * @return the result */ public static Result movedPermanently(String url) { return new Result(MOVED_PERMANENTLY, Collections.singletonMap(LOCATION, url)); }
/** * Generates a 302 Found result. * * @param url The url to redirect. * @return the result */ public static Result found(String url) { return new Result(FOUND, Collections.singletonMap(LOCATION, url)); }
/** * Generates a 303 See Other result. * * @param call Call defining the url to redirect (typically comes from reverse router). * @return the result */ public static Result seeOther(Call call) { return new Result(SEE_OTHER, Collections.singletonMap(LOCATION, call.path())); }
/** * Return a copy of this result with the given header. * * @param name the header name * @param value the header value * @return the transformed copy */ public Result withHeader(String name, String value) { return new Result(header.withHeader(name, value), body, session, flash, cookies); }
/** * Return a copy of the result with a different Content-Type header. * * @param contentType the content type to set * @return the transformed copy */ public Result as(String contentType) { return new Result(header, body.as(contentType)); }
/** * Generates a 303 See Other result. * * @param call Call defining the url to redirect (typically comes from reverse router). * @return the result */ public static Result seeOther(Call call) { return new Result(SEE_OTHER, Collections.singletonMap(LOCATION, call.path())); }
/** * Generates a 307 Temporary Redirect result. * * @param call Call defining the url to redirect (typically comes from reverse router). * @return the result */ public static Result temporaryRedirect(Call call) { return new Result(TEMPORARY_REDIRECT, Collections.singletonMap(LOCATION, call.path())); }
/** * Return a copy of this result with the given headers. * * The headers are processed in pairs, so nameValues(0) is the first header's name, and * nameValues(1) is the first header's value, nameValues(2) is second header's name, * and so on. * * @param nameValues the array of names and values. * @return the transformed copy */ public Result withHeaders(String... nameValues) { return new Result(JavaResultExtractor.withHeader(header, nameValues), body, session, flash, cookies); }
/** * Return a copy of this result with the given header. * * @param name the header name * @param value the header value * @return the transformed copy */ public Result withHeader(String name, String value) { return new Result(header.withHeader(name, value), body, session, flash, cookies); }
/** * Discard a HTTP header in this result. * * @param name the header name * @return the transformed copy */ public Result withoutHeader(String name) { return new Result(header.withoutHeader(name), body, session, flash, cookies); }
/** * Return a copy of this result with the given header. * * @param name the header name * @param value the header value * @return the transformed copy */ public Result withHeader(String name, String value) { return new Result(header.withHeader(name, value), body, session, flash, cookies); }
/** * Generates a 302 Found result. * * @param call Call defining the url to redirect (typically comes from reverse router). * @return the result */ public static Result found(Call call) { return new Result(FOUND, Collections.singletonMap(LOCATION, call.path())); }
/** * Send a chunked response with the given chunks. * * @param chunks the chunks to send * @return a '200 OK' response with the given chunks. */ public Result chunked(Source<ByteString, ?> chunks) { return new Result(status(), HttpEntity.chunked(chunks, Optional.empty())); }
/** * Send a streamed response with the given source. * * @param body the source to send * @param contentLength the entity content length. * @param contentType the entity content type. * @return a '200 OK' response with the given body. */ public Result streamed(Source<ByteString, ?> body, Optional<Long> contentLength, Optional<String> contentType) { return new Result(status(), new HttpEntity.Streamed(body, contentLength, contentType)); }