public interface Response
Modifier and Type | Interface and Description |
---|---|
static class |
Response.Forwarding
A forwarding response.
|
Modifier and Type | Method and Description |
---|---|
Charset |
charset()
If charset is not set this method returns charset defined in the request body.
|
Response |
charset(Charset charset)
Set the
Charset to use and set the Content-Type header with the current
charset. |
Response |
clearCookie(String name)
Discard a cookie from response.
|
boolean |
committed()
Returns a boolean indicating if the response has been committed.
|
default Response |
cookie(Cookie.Definition cookie)
Adds the specified cookie to the response.
|
Response |
cookie(Cookie cookie)
Adds the specified cookie to the response.
|
default Response |
cookie(String name,
String value)
Adds the specified cookie to the response.
|
default void |
download(File file)
Transfer the file at path as an "attachment".
|
default void |
download(String location)
Transfer the file at path as an "attachment".
|
default void |
download(String filename,
File file)
Transfer the file at path as an "attachment".
|
void |
download(String filename,
InputStream stream)
Transfer the file at path as an "attachment".
|
void |
download(String filename,
String location)
Transfer the file at path as an "attachment".
|
void |
end()
Ends current request/response cycle by releasing any existing resources and committing the
response into the channel.
|
Mutant |
header(String name)
Get a header with the given name.
|
Response |
header(String name,
Iterable<Object> values)
Sets a response header with the given name and value.
|
default Response |
header(String name,
Object... values)
Sets a response header with the given name and value.
|
Response |
header(String name,
Object value)
Sets a response header with the given name and value.
|
Response |
length(long length)
Set the length of the response and set the
Content-Length header. |
void |
redirect(Status status,
String location)
Redirect to the given url with status code defaulting to
Status.FOUND . |
default void |
redirect(String location)
Redirect to the given url with status code defaulting to
Status.FOUND . |
default void |
send(Object result)
Responsible of writing the given body into the HTTP response.
|
void |
send(Result result)
Responsible of writing the given body into the HTTP response.
|
Optional<Status> |
status() |
default Response |
status(int status)
Set the HTTP response status.
|
Response |
status(Status status)
Set the HTTP response status.
|
Optional<MediaType> |
type() |
Response |
type(MediaType type)
Set the response media type and set the
Content-Type header. |
default Response |
type(String type)
Set the response media type and set the
Content-Type header. |
void download(String filename, InputStream stream) throws Exception
Content-Disposition
"filename=" parameter (i.e. the one that will
appear in the browser dialog) is set to filename.filename
- A file name to use.stream
- A stream to attach.Exception
- If something goes wrong.default void download(String location) throws Exception
Content-Disposition
"filename=" parameter (i.e. the one that will
appear in the browser dialog) is set to filename by default.location
- Classpath location of the file.Exception
- If something goes wrong.void download(String filename, String location) throws Exception
Content-Disposition
"filename=" parameter (i.e. the one that will
appear in the browser dialog) is set to filename by default.filename
- A file name to use.location
- classpath location of the file.Exception
- If something goes wrong.default void download(File file) throws Exception
Content-Disposition
"filename=" parameter (i.e. the one that will
appear in the browser dialog) is set to filename by default.file
- A file to use.Exception
- If something goes wrong.default void download(String filename, File file) throws Exception
Content-Disposition
"filename=" parameter (i.e. the one that will
appear in the browser dialog) is set to filename.filename
- A file name to use.file
- A file to use.Exception
- If something goes wrong.default Response cookie(String name, String value)
name
- A cookie's name.value
- A cookie's value.default Response cookie(Cookie.Definition cookie)
cookie
- A cookie definition.Response cookie(Cookie cookie)
cookie
- A cookie.Response clearCookie(String name)
name
- Cookie's name.Mutant header(String name)
name
- A name.Response header(String name, Object value)
name
- Header's name.value
- Header's value.default Response header(String name, Object... values)
name
- Header's name.values
- Header's value.Response header(String name, Iterable<Object> values)
name
- Header's name.values
- Header's value.Charset charset()
application.charset
.Response charset(Charset charset)
Charset
to use and set the Content-Type
header with the current
charset.charset
- A charset.Response length(long length)
Content-Length
header.length
- Length of response.Response type(MediaType type)
Content-Type
header.type
- A media type.default Response type(String type)
Content-Type
header.type
- A media type.default void send(Object result) throws Exception
result
- The HTTP body.Exception
- If the response write fails.void send(Result result) throws Exception
result
- A HTTP response.Exception
- If the response write fails.default void redirect(String location) throws Exception
Status.FOUND
.
rsp.redirect("/foo/bar"); rsp.redirect("http://example.com"); rsp.redirect("http://example.com"); rsp.redirect("../login");Redirects can be a fully qualified URI for redirecting to a different site:
rsp.redirect("http://google.com");Redirects can be relative to the root of the host name. For example, if you were on
http://example.com/admin/post/new
, the following redirect to /admin would
land you at http://example.com/admin
:
rsp.redirect("/admin");Redirects can be relative to the current URL. A redirection of post/new, from
http://example.com/blog/admin/
(notice the trailing slash), would give you
http://example.com/blog/admin/post/new.
rsp.redirect("post/new");Redirecting to post/new from
http://example.com/blog/admin
(no trailing slash),
will take you to http://example.com/blog/post/new
.
If you found the above behavior confusing, think of path segments as directories (have trailing slashes) and files, it will start to make sense.
Pathname relative redirects are also possible. If you were onhttp://example.com/admin/post/new
, the following redirect would land you at
http//example.com/admin
:
rsp.redirect("..");A back redirection will redirect the request back to the
Referer
, defaulting to
/
when missing.
rsp.redirect("back");
location
- Either a relative or absolute location.Exception
- If redirection fails.void redirect(Status status, String location) throws Exception
Status.FOUND
.
rsp.redirect("/foo/bar"); rsp.redirect("http://example.com"); rsp.redirect("http://example.com"); rsp.redirect("../login");Redirects can be a fully qualified URI for redirecting to a different site:
rsp.redirect("http://google.com");Redirects can be relative to the root of the host name. For example, if you were on
http://example.com/admin/post/new
, the following redirect to /admin would
land you at http://example.com/admin
:
rsp.redirect("/admin");Redirects can be relative to the current URL. A redirection of post/new, from
http://example.com/blog/admin/
(notice the trailing slash), would give you
http://example.com/blog/admin/post/new.
rsp.redirect("post/new");Redirecting to post/new from
http://example.com/blog/admin
(no trailing slash),
will take you to http://example.com/blog/post/new
.
If you found the above behavior confusing, think of path segments as directories (have trailing slashes) and files, it will start to make sense.
Pathname relative redirects are also possible. If you were onhttp://example.com/admin/post/new
, the following redirect would land you at
http//example.com/admin
:
rsp.redirect("..");A back redirection will redirect the request back to the
Referer
, defaulting to
/
when missing.
rsp.redirect("back");
status
- A redirect status.location
- Either a relative or absolute location.Exception
- If redirection fails.Response status(Status status)
status
- A HTTP status.default Response status(int status)
status
- A HTTP status.boolean committed()
void end()
rsp.status(304).end();Keep in mind that an explicit call to this method will stop the execution of handlers. So, any handler further in the chain won't be executed once end has been called.
Copyright © 2015. All rights reserved.