Response.Forwarding
Constructor and Description |
---|
ResponseImpl(com.google.inject.Injector injector,
NativeResponse rsp,
Route route,
Map<String,Object> locals,
Charset charset,
Optional<String> referer) |
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.
|
Response |
cookie(Cookie cookie)
Adds the specified cookie to the response.
|
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.
|
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 . |
void |
reset() |
void |
send(Result result)
Responsible of writing the given body into the HTTP response.
|
Optional<Status> |
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. |
public void download(String filename, InputStream stream) throws Exception
Response
Content-Disposition
"filename=" parameter (i.e. the one that will
appear in the browser dialog) is set to filename.public void download(String filename, String location) throws Exception
Response
Content-Disposition
"filename=" parameter (i.e. the one that will
appear in the browser dialog) is set to filename by default.public Response cookie(Cookie cookie)
Response
public Response clearCookie(String name)
Response
clearCookie
in interface Response
name
- Cookie's name.public Mutant header(String name)
Response
public Response header(String name, Object value)
Response
public Response header(String name, Iterable<Object> values)
Response
public Charset charset()
Response
application.charset
.public Response charset(Charset charset)
Response
Charset
to use and set the Content-Type
header with the current
charset.public Response length(long length)
Response
Content-Length
header.public Response type(MediaType type)
Response
Content-Type
header.public void redirect(Status status, String location) throws Exception
Response
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");
public Response status(Status status)
Response
public boolean committed()
Response
public void end()
Response
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.
public void send(Result result) throws Exception
Response
public void reset()
Copyright © 2015. All rights reserved.