Class CookieEncoder
- java.lang.Object
-
- org.jboss.netty.handler.codec.http.CookieEncoder
-
public class CookieEncoder extends java.lang.ObjectEncodesCookies 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 theaddCookie(String, String)method. Onceencode()is called, all addedCookies are encoded into an HTTP header value and allCookies in the internal data structure are removed so that the encoder can start over.// Client-side example
HttpRequestreq = ...;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());- 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 voidaddCookie(java.lang.String name, java.lang.String value)Adds a newCookiecreated with the specified name and value to this encoder.voidaddCookie(Cookie cookie)Adds the specifiedCookieto this encoder.java.lang.Stringencode()Encodes theCookies which were added byaddCookie(Cookie)so far into an HTTP header value.private java.lang.StringencodeClientSide()private java.lang.StringencodeServerSide()
-
-
-
Field Detail
-
cookies
private final java.util.Set<Cookie> cookies
-
server
private final boolean server
-
strict
private final boolean strict
-
-
Constructor Detail
-
CookieEncoder
public CookieEncoder(boolean server)
Creates a new encoder.- Parameters:
server-trueif and only if this encoder is supposed to encode server-side cookies.falseif 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-trueif and only if this encoder is supposed to encode server-side cookies.falseif and only if this encoder is supposed to encode client-side cookies.strict-trueif and only if this encoder is supposed to validate characters according to RFC6265.
-
-
Method Detail
-
addCookie
public void addCookie(java.lang.String name, java.lang.String value)Adds a newCookiecreated with the specified name and value to this encoder.
-
encode
public java.lang.String encode()
Encodes theCookies which were added byaddCookie(Cookie)so far into an HTTP header value. If noCookies were added, an empty string is returned. Be aware that calling this method will clear the content of theCookieEncoder
-
encodeServerSide
private java.lang.String encodeServerSide()
-
encodeClientSide
private java.lang.String encodeClientSide()
-
-