
public class CookieEncoder extends Object
Cookies into an HTTP header value. This encoder can encode
the HTTP cookie version 0, 1, and 2.
This encoder is stateful. It maintains an internal data structure that
holds the Cookies added by the addCookie(String, String)
method. Once encode() is called, all added Cookies are
encoded into an HTTP header value and all Cookies in the internal
data structure are removed so that the encoder can start over.
// Client-side exampleHttpRequestreq = ...;CookieEncoderencoder = newCookieEncoder(false); encoder.addCookie("JSESSIONID", "1234"); res.setHeader("Cookie", encoder.encode()); // Server-side exampleHttpResponseres = ...;CookieEncoderencoder = newCookieEncoder(true); encoder.addCookie("JSESSIONID", "1234"); res.setHeader("Set-Cookie", encoder.encode());
CookieDecoder| Constructor and Description |
|---|
CookieEncoder(boolean server)
Creates a new encoder.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addCookie(Cookie cookie)
Adds the specified
Cookie to this encoder. |
void |
addCookie(String name,
String value)
Adds a new
Cookie created with the specified name and value to
this encoder. |
String |
encode()
Encodes the
Cookies which were added by addCookie(Cookie)
so far into an HTTP header value. |
public CookieEncoder(boolean server)
server - true if and only if this encoder is supposed to
encode server-side cookies. false if and only if
this encoder is supposed to encode client-side cookies.public void addCookie(String name, String value)
Cookie created with the specified name and value to
this encoder.public String encode()
Cookies which were added by addCookie(Cookie)
so far into an HTTP header value. If no Cookies were added,
an empty string is returned.
Be aware that calling this method will clear the content of the CookieEncoderCopyright © 2008-2013 The Netty Project. All Rights Reserved.