Class CookieEncoder
- java.lang.Object
-
- org.jboss.netty.handler.codec.http.CookieEncoder
-
public class CookieEncoder extends Object
EncodesCookie
s 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
Cookie
s added by theaddCookie(String, String)
method. Onceencode()
is called, all addedCookie
s are encoded into an HTTP header value and allCookie
s in the internal data structure are removed so that the encoder can start over.// Client-side example
HttpRequest
req = ...;CookieEncoder
encoder = newCookieEncoder
(false); encoder.addCookie("JSESSIONID", "1234"); res.setHeader("Cookie", encoder.encode()); // Server-side exampleHttpResponse
res = ...;CookieEncoder
encoder = newCookieEncoder
(true); encoder.addCookie("JSESSIONID", "1234"); res.setHeader("Set-Cookie", encoder.encode());- See Also:
CookieDecoder
-
-
Constructor Summary
Constructors Constructor Description CookieEncoder(boolean server)
Creates a new encoder.CookieEncoder(boolean server, boolean strict)
Creates a new encoder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCookie(String name, String value)
Adds a newCookie
created with the specified name and value to this encoder.void
addCookie(Cookie cookie)
Adds the specifiedCookie
to this encoder.String
encode()
Encodes theCookie
s which were added byaddCookie(Cookie)
so far into an HTTP header value.
-
-
-
Constructor Detail
-
CookieEncoder
public CookieEncoder(boolean server)
Creates a new encoder.- Parameters:
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.
-
CookieEncoder
public CookieEncoder(boolean server, boolean strict)
Creates a new encoder.- Parameters:
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.strict
-true
if and only if this encoder is supposed to validate characters according to RFC6265.
-
-
Method Detail
-
addCookie
public void addCookie(String name, String value)
Adds a newCookie
created with the specified name and value to this encoder.
-
encode
public String encode()
Encodes theCookie
s which were added byaddCookie(Cookie)
so far into an HTTP header value. If noCookie
s were added, an empty string is returned. Be aware that calling this method will clear the content of theCookieEncoder
-
-