Package play.mvc
Class Http.Response
- java.lang.Object
-
- play.mvc.Http.Response
-
- Enclosing class:
- Http
public static class Http.Response extends java.lang.ObjectAn HTTP response
-
-
Field Summary
Fields Modifier and Type Field Description booleanchunkedjava.lang.StringcontentTypeResponse content typejava.util.Map<java.lang.String,Http.Cookie>cookiesResponse cookiesstatic java.lang.ThreadLocal<Http.Response>currentBind to threadjava.lang.ObjectdirectSend this file directlyjava.lang.StringencodingThe encoding used when writing response to clientjava.util.Map<java.lang.String,Http.Header>headersResponse headersjava.io.ByteArrayOutputStreamoutResponse body streamjava.lang.IntegerstatusResponse status code
-
Constructor Summary
Constructors Constructor Description Response()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccessControl(java.lang.String allowOrigin)Add headers to allow cross-domain requests.voidaccessControl(java.lang.String allowOrigin, boolean allowCredentials)Add headers to allow cross-domain requests.voidaccessControl(java.lang.String allowOrigin, java.lang.String allowMethods, boolean allowCredentials)Add headers to allow cross-domain requests.voidcacheFor(java.lang.String duration)Add a cache-control headervoidcacheFor(java.lang.String etag, java.lang.String duration, long lastModified)Add cache-control headersstatic Http.Responsecurrent()Retrieve the current responsejava.lang.StringgetHeader(java.lang.String name)Get a response headervoidonWriteChunk(F.Action<java.lang.Object> handler)voidprint(java.lang.Object o)voidremoveCookie(java.lang.String name)Removes the specified cookie with path /voidremoveCookie(java.lang.String name, java.lang.String path)Removes the cookievoidreset()voidsetContentTypeIfNotSet(java.lang.String contentType)voidsetCookie(java.lang.String name, java.lang.String value)Set a new cookievoidsetCookie(java.lang.String name, java.lang.String value, java.lang.String duration)Set a new cookie that will expire in (current) + durationvoidsetCookie(java.lang.String name, java.lang.String value, java.lang.String domain, java.lang.String path, java.lang.Integer maxAge, boolean secure)voidsetCookie(java.lang.String name, java.lang.String value, java.lang.String domain, java.lang.String path, java.lang.Integer maxAge, boolean secure, boolean httpOnly)voidsetHeader(java.lang.String name, java.lang.String value)Set a response headervoidwriteChunk(java.lang.Object o)
-
-
-
Field Detail
-
status
public java.lang.Integer status
Response status code
-
contentType
public java.lang.String contentType
Response content type
-
headers
public java.util.Map<java.lang.String,Http.Header> headers
Response headers
-
cookies
public java.util.Map<java.lang.String,Http.Cookie> cookies
Response cookies
-
out
public java.io.ByteArrayOutputStream out
Response body stream
-
direct
public java.lang.Object direct
Send this file directly
-
encoding
public java.lang.String encoding
The encoding used when writing response to client
-
current
public static final java.lang.ThreadLocal<Http.Response> current
Bind to thread
-
chunked
public boolean chunked
-
-
Method Detail
-
current
public static Http.Response current()
Retrieve the current response- Returns:
- the current response
-
getHeader
public java.lang.String getHeader(java.lang.String name)
Get a response header- Parameters:
name- Header name case-insensitive- Returns:
- the header value as a String
-
setHeader
public void setHeader(java.lang.String name, java.lang.String value)Set a response header- Parameters:
name- Header namevalue- Header value
-
setContentTypeIfNotSet
public void setContentTypeIfNotSet(java.lang.String contentType)
-
setCookie
public void setCookie(java.lang.String name, java.lang.String value)Set a new cookie- Parameters:
name- Cookie namevalue- Cookie value
-
removeCookie
public void removeCookie(java.lang.String name)
Removes the specified cookie with path /- Parameters:
name- cookie name
-
removeCookie
public void removeCookie(java.lang.String name, java.lang.String path)Removes the cookie- Parameters:
name- cookie namepath- cookie path
-
setCookie
public void setCookie(java.lang.String name, java.lang.String value, java.lang.String duration)Set a new cookie that will expire in (current) + duration- Parameters:
name- the cookie namevalue- The cookie valueduration- the cookie duration (Ex: 3d)
-
setCookie
public void setCookie(java.lang.String name, java.lang.String value, java.lang.String domain, java.lang.String path, java.lang.Integer maxAge, boolean secure)
-
setCookie
public void setCookie(java.lang.String name, java.lang.String value, java.lang.String domain, java.lang.String path, java.lang.Integer maxAge, boolean secure, boolean httpOnly)
-
cacheFor
public void cacheFor(java.lang.String duration)
Add a cache-control header- Parameters:
duration- Ex: 3h
-
cacheFor
public void cacheFor(java.lang.String etag, java.lang.String duration, long lastModified)Add cache-control headers- Parameters:
etag- the Etag valueduration- the cache duration (Ex: 3h)lastModified- The last modified date
-
accessControl
public void accessControl(java.lang.String allowOrigin)
Add headers to allow cross-domain requests. Be careful, a lot of browsers don't support these features and will ignore the headers. Refer to the browsers' documentation to know what versions support them.- Parameters:
allowOrigin- a comma separated list of domains allowed to perform the x-domain call, or "*" for all.
-
accessControl
public void accessControl(java.lang.String allowOrigin, boolean allowCredentials)Add headers to allow cross-domain requests. Be careful, a lot of browsers don't support these features and will ignore the headers. Refer to the browsers' documentation to know what versions support them.- Parameters:
allowOrigin- a comma separated list of domains allowed to perform the x-domain call, or "*" for all.allowCredentials- Let the browser send the cookies when doing a x-domain request. Only respected by the browser if allowOrigin != "*"
-
accessControl
public void accessControl(java.lang.String allowOrigin, java.lang.String allowMethods, boolean allowCredentials)Add headers to allow cross-domain requests. Be careful, a lot of browsers don't support these features and will ignore the headers. Refer to the browsers' documentation to know what versions support them.- Parameters:
allowOrigin- a comma separated list of domains allowed to perform the x-domain call, or "*" for all.allowMethods- a comma separated list of HTTP methods allowed, or null for all.allowCredentials- Let the browser send the cookies when doing a x-domain request. Only respected by the browser if allowOrigin != "*"
-
print
public void print(java.lang.Object o)
-
reset
public void reset()
-
writeChunk
public void writeChunk(java.lang.Object o)
-
onWriteChunk
public void onWriteChunk(F.Action<java.lang.Object> handler)
-
-