Package org.apache.tapestry5
Class CookieBuilder
java.lang.Object
org.apache.tapestry5.CookieBuilder
A fluent API to create and write cookies. Used by the
Cookies
service.- Since:
- 5.4
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
CookieBuilder
(String name, String value) Initialize a new CookieBuilder -
Method Summary
Modifier and TypeMethodDescriptionabstract void
delete()
Deletes the cookie.setComment
(String comment) Comments are not supported by version 0 (the default) cookiesSet the domain for the cookie to be created.setHttpOnly
(boolean httpOnly) Set the cookie's httpOnly mode.setMaxAge
(int maxAge) Set how long the cookie should live.Set how long the cookie should live.Set the path for the cookie to be created.setSecure
(boolean secure) Set the cookie's secure mode.setVersion
(int version) Version 0 complies with the original Netscape cookie specification.abstract void
write()
Sets defaults and writes the cookie to the client.
-
Field Details
-
name
-
value
-
path
-
domain
-
maxAge
-
secure
-
httpOnly
-
version
-
comment
-
-
Constructor Details
-
CookieBuilder
Initialize a new CookieBuilder- Parameters:
name
- the name of the resulting cookievalue
- the value of the resulting cookie
-
-
Method Details
-
setPath
Set the path for the cookie to be created. Defaults toRequest.getContextPath()
.- Parameters:
path
- the path for the cookie- Returns:
- the modified
CookieBuilder
-
setDomain
Set the domain for the cookie to be created. Will not be set by default.- Parameters:
domain
- the domain for the cookie- Returns:
- the modified
CookieBuilder
-
setMaxAge
Set how long the cookie should live. A value of0
deletes a cookie, a value of-1
deletes a cookie upon closing the browser. The default is defined by the symbolorg.apache.tapestry5.default-cookie-max-age
. The factory default for this value is the equivalent of one week.- Parameters:
maxAge
- the cookie's maximum age in seconds- Returns:
- the modified
CookieBuilder
-
setMaxAge
Set how long the cookie should live. A value ofjava.time.Duration.ZERO
deletes a cookie, a negative value deletes a cookie upon closing the browser. The default is defined by the symbolorg.apache.tapestry5.default-cookie-max-age
. The factory default for this value is the equivalent of one week.- Parameters:
maxAge
- the cookie's maximum age in seconds- Returns:
- the modified
CookieBuilder
- Since:
- 5.8.3
-
setSecure
Set the cookie's secure mode. Defaults toRequest.isSecure()
.- Parameters:
secure
- whether to send the cookie over a secure channel only- Returns:
- the modified
CookieBuilder
-
setHttpOnly
Set the cookie's httpOnly mode.- Parameters:
httpOnly
- prevents javascript access to this cookie- Returns:
- the modified
CookieBuilder
-
setVersion
Version 0 complies with the original Netscape cookie specification. Version 1 complies with RFC 2109 (experimental)- Parameters:
version
- number- Returns:
- the modified
CookieBuilder
-
setComment
Comments are not supported by version 0 (the default) cookies- Parameters:
comment
- for cookie- Returns:
- the modified
CookieBuilder
-
write
Sets defaults and writes the cookie to the client. -
delete
Deletes the cookie.
-