Top Description Fields Constructors Methods
io.netty.handler.codec.http.cookie

public final Class ServerCookieEncoder

extends CookieEncoder
Class Inheritance
Imports
io.netty.handler.codec.DateFormatter, io.netty.handler.codec.http.HttpConstants, .HttpResponse, java.util.ArrayList, .Collection, .Collections, .Date, .HashMap, .Iterator, .List, .Map

A RFC6265 compliant cookie encoder to be used server side, so some fields are sent (Version is typically ignored). As Netty's Cookie merges Expires and MaxAge into one single field, only Max-Age field is sent. Note that multiple cookies must be sent as separate "Set-Cookie" headers.
// Example
HttpResponse res = ...;
res.setHeader("Set-Cookie", ServerCookieEncoder.encode("JSESSIONID", "1234"));
See Also
ServerCookieDecoder

Field Summary

Modifier and TypeField and Description
public static final ServerCookieEncoder
LAX

Lax instance that doesn't validate name and value, and that allows multiple cookies with the same name.

public static final ServerCookieEncoder
STRICT

Strict encoder that validates that name and value chars are in the valid scope defined in RFC6265, and (for methods that accept multiple cookies) that only one cookie is encoded with any given name.

Inherited from io.netty.handler.codec.http.cookie.CookieEncoder:
strict

Constructor Summary

AccessConstructor and Description
private
ServerCookieEncoder(boolean strict)

Method Summary

Modifier and TypeMethod and Description
private static List<String>

Returns:

The encoded list with all but the last instance of a named cookie.
dedup
(List<String>
The list of encoded cookies.
encoded
,
Map<String, Integer>
A map from cookie name to index of last cookie instance.
nameToLastIndex
)

Deduplicate a list of encoded cookies by keeping only the last instance with a given name.

public String

Returns:

a single Set-Cookie header value
encode
(String
the cookie name
name
,
String
the cookie value
value
)

Encodes the specified cookie name-value pair into a Set-Cookie header value.

public String

Returns:

a single Set-Cookie header value
encode
(Cookie
the cookie
cookie
)

Encodes the specified cookie into a Set-Cookie header value.

public List<String>

Returns:

the corresponding bunch of Set-Cookie headers
encode
(Cookie...
a bunch of cookies
cookies
)

Batch encodes cookies into Set-Cookie header values.

public List<String>

Returns:

the corresponding bunch of Set-Cookie headers
encode
(Collection<? extends Cookie>
a bunch of cookies
cookies
)

Batch encodes cookies into Set-Cookie header values.

public List<String>

Returns:

the corresponding bunch of Set-Cookie headers
encode
(Iterable<? extends Cookie>
a bunch of cookies
cookies
)

Batch encodes cookies into Set-Cookie header values.

Inherited from io.netty.handler.codec.http.cookie.CookieEncoder:
validateCookie

Field Detail

LAXback to summary
public static final ServerCookieEncoder LAX

Lax instance that doesn't validate name and value, and that allows multiple cookies with the same name.

STRICTback to summary
public static final ServerCookieEncoder STRICT

Strict encoder that validates that name and value chars are in the valid scope defined in RFC6265, and (for methods that accept multiple cookies) that only one cookie is encoded with any given name. (If multiple cookies have the same name, the last one is the one that is encoded.)

Constructor Detail

ServerCookieEncoderback to summary
private ServerCookieEncoder(boolean strict)

Method Detail

dedupback to summary
private static List<String> dedup(List<String> encoded, Map<String, Integer> nameToLastIndex)

Deduplicate a list of encoded cookies by keeping only the last instance with a given name.

Parameters
encoded:List<String>

The list of encoded cookies.

nameToLastIndex:Map<String, Integer>

A map from cookie name to index of last cookie instance.

Returns:List<String>

The encoded list with all but the last instance of a named cookie.

encodeback to summary
public String encode(String name, String value)

Encodes the specified cookie name-value pair into a Set-Cookie header value.

Parameters
name:String

the cookie name

value:String

the cookie value

Returns:String

a single Set-Cookie header value

encodeback to summary
public String encode(Cookie cookie)

Encodes the specified cookie into a Set-Cookie header value.

Parameters
cookie:Cookie

the cookie

Returns:String

a single Set-Cookie header value

encodeback to summary
public List<String> encode(Cookie... cookies)

Batch encodes cookies into Set-Cookie header values.

Parameters
cookies:Cookie[]

a bunch of cookies

Returns:List<String>

the corresponding bunch of Set-Cookie headers

encodeback to summary
public List<String> encode(Collection<? extends Cookie> cookies)

Batch encodes cookies into Set-Cookie header values.

Parameters
cookies:Collection<? extends Cookie>

a bunch of cookies

Returns:List<String>

the corresponding bunch of Set-Cookie headers

encodeback to summary
public List<String> encode(Iterable<? extends Cookie> cookies)

Batch encodes cookies into Set-Cookie header values.

Parameters
cookies:Iterable<? extends Cookie>

a bunch of cookies

Returns:List<String>

the corresponding bunch of Set-Cookie headers