public interface Cookie
A cookie has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum age, and a version number.
The server sends cookies to the browser by using the Response.cookie(Cookie)
method,
which adds fields to HTTP response headers to send cookies to the browser, one at a time. The
browser is expected to support 20 cookies for each Web server, 300 cookies total, and may limit
cookie size to 4 KB each.
The browser returns cookies to the server by adding fields to HTTP request headers. Cookies can
be retrieved from a request by using the Request.cookie(String)
method. Several cookies
might have the same name but different path attributes.
This class supports both the Version 0 (by Netscape) and Version 1 (by RFC 2109) cookie specifications. By default, cookies are created using Version 0 to ensure the best interoperability.
Modifier and Type | Interface and Description |
---|---|
static class |
Cookie.Definition
Build a
Cookie . |
static class |
Cookie.Signature
Sign cookies using a HMAC algorithm plus SHA-256 hash.
|
Modifier and Type | Method and Description |
---|---|
Optional<String> |
comment() |
Optional<String> |
domain() |
String |
encode() |
boolean |
httpOnly() |
int |
maxAge()
Gets the maximum age of this cookie (in seconds).
|
String |
name() |
Optional<String> |
path() |
boolean |
secure()
Returns
true if the browser is sending cookies only over a secure protocol, or
false if the browser can send cookies using any protocol. |
Optional<String> |
value() |
String name()
int maxAge()
By default, -1
is returned, which indicates that the cookie will persist until
browser shutdown.
boolean secure()
true
if the browser is sending cookies only over a secure protocol, or
false
if the browser can send cookies using any protocol.true
if the browser uses a secure protocol, false
otherwise.boolean httpOnly()
String encode()
Copyright © 2015. All rights reserved.