public interface Response
Modifier and Type | Interface and Description |
---|---|
static class |
Response.Forwarding
A forwarding response.
|
Modifier and Type | Method and Description |
---|---|
void |
after(Route.After handler)
Append an after handler, will be execute before sending response.
|
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.
|
void |
complete(Route.Complete handler)
Append complete handler, will be execute after sending response.
|
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.
|
boolean |
isResetHeadersOnError()
Indicates if headers are cleared/reset on error.
|
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.
|
void |
setResetHeadersOnError(boolean value)
Indicates if headers are cleared/reset on error.
|
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 Throwable
Content-Disposition
"filename=" parameter (i.e. the one that will appear in the browser dialog) is set to filename.
default void download(String location) throws Throwable
Content-Disposition
"filename=" parameter (i.e. the one that will appear in the browser dialog) is set to filename by default.
void download(String filename, String location) throws Throwable
Content-Disposition
"filename=" parameter (i.e. the one that will appear in the browser dialog) is set to filename by default.
default void download(File file) throws Throwable
Content-Disposition
"filename=" parameter (i.e. the one that will appear in the browser dialog) is set to filename by default.
default void download(String filename, File file) throws Throwable
Content-Disposition
"filename=" parameter (i.e. the one that will appear in the browser dialog) is set to filename.
@Nonnull default Response cookie(String name, String value)
name
- A cookie's name.
value
- A cookie's value.
@Nonnull Response cookie(Cookie.Definition cookie)
cookie
- A cookie definition.
@Nonnull Response cookie(Cookie cookie)
cookie
- A cookie.
@Nonnull Response clearCookie(String name)
name
- Cookie's name.
@Nonnull Mutant header(String name)
name
- A name.
@Nonnull Response header(String name, Object value)
name
- Header's name.
value
- Header's value.
@Nonnull default Response header(String name, Object... values)
name
- Header's name.
values
- Header's value.
@Nonnull Response header(String name, Iterable<Object> values)
name
- Header's name.
values
- Header's value.
@Nonnull Charset charset()
application.charset
.
@Nonnull Response charset(Charset charset)
Charset
to use and set the Content-Type
header with the current charset.
charset
- A charset.
@Nonnull Response length(long length)
Content-Length
header.
length
- Length of response.
@Nonnull Response type(MediaType type)
Content-Type
header.
type
- A media type.
@Nonnull default Response type(String type)
Content-Type
header.
type
- A media type.
default void send(@Nullable Object result) throws Throwable
void send(Result result) throws Throwable
default void redirect(String location) throws Throwable
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.
Throwable
- If redirection fails.
void redirect(Status status, String location) throws Throwable
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.
Throwable
- If redirection fails.
@Nonnull Optional<Status> status()
@Nonnull Response status(Status status)
status
- A HTTP status.
@Nonnull 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.
void after(Route.After handler)
handler
- A handler
Route.After
void complete(Route.Complete handler)
handler
- A handler
Route.After
boolean isResetHeadersOnError()
void setResetHeadersOnError(boolean value)
value
- True to reset.
Copyright © 2019. All rights reserved.