Home / Class/ ClientCookieEncoder Class — netty Architecture

ClientCookieEncoder Class — netty Architecture

Architecture documentation for the ClientCookieEncoder class in ClientCookieEncoder.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  d4f95fd7_6f76_5a0b_7a19_2f8835ae7075["ClientCookieEncoder"]
  564c9f5e_2948_76b1_b336_cf97b1ba8d60["ClientCookieEncoder.java"]
  d4f95fd7_6f76_5a0b_7a19_2f8835ae7075 -->|defined in| 564c9f5e_2948_76b1_b336_cf97b1ba8d60
  afe13e28_f109_dd45_e5e5_92c6dbe3308e["ClientCookieEncoder()"]
  d4f95fd7_6f76_5a0b_7a19_2f8835ae7075 -->|method| afe13e28_f109_dd45_e5e5_92c6dbe3308e
  270c0071_04c2_21b8_07c0_12b04192cdfb["String()"]
  d4f95fd7_6f76_5a0b_7a19_2f8835ae7075 -->|method| 270c0071_04c2_21b8_07c0_12b04192cdfb
  d863c2c7_1fe5_8ac8_3dae_4cc17dbd12d5["encode()"]
  d4f95fd7_6f76_5a0b_7a19_2f8835ae7075 -->|method| d863c2c7_1fe5_8ac8_3dae_4cc17dbd12d5

Relationship Graph

Source Code

codec-http/src/main/java/io/netty/handler/codec/http/cookie/ClientCookieEncoder.java lines 47–225

public final class ClientCookieEncoder extends CookieEncoder {

    /**
     * Strict encoder that validates that name and value chars are in the valid scope and (for methods that accept
     * multiple cookies) sorts cookies into order of decreasing path length, as specified in RFC6265.
     */
    public static final ClientCookieEncoder STRICT = new ClientCookieEncoder(true);

    /**
     * Lax instance that doesn't validate name and value, and (for methods that accept multiple cookies) keeps
     * cookies in the order in which they were given.
     */
    public static final ClientCookieEncoder LAX = new ClientCookieEncoder(false);

    private ClientCookieEncoder(boolean strict) {
        super(strict);
    }

    /**
     * Encodes the specified cookie into a Cookie header value.
     *
     * @param name
     *            the cookie name
     * @param value
     *            the cookie value
     * @return a Rfc6265 style Cookie header value
     */
    public String encode(String name, String value) {
        return encode(new DefaultCookie(name, value));
    }

    /**
     * Encodes the specified cookie into a Cookie header value.
     *
     * @param cookie the specified cookie
     * @return a Rfc6265 style Cookie header value
     */
    public String encode(Cookie cookie) {
        StringBuilder buf = stringBuilder();
        encode(buf, checkNotNull(cookie, "cookie"));
        return stripTrailingSeparator(buf);
    }

    /**
     * Sort cookies into decreasing order of path length, breaking ties by sorting into increasing chronological
     * order of creation time, as recommended by RFC 6265.
     */
    // package-private for testing only.
    static final Comparator<Cookie> COOKIE_COMPARATOR = new Comparator<Cookie>() {
        @Override
        public int compare(Cookie c1, Cookie c2) {
            String path1 = c1.path();
            String path2 = c2.path();
            // Cookies with unspecified path default to the path of the request. We don't
            // know the request path here, but we assume that the length of an unspecified
            // path is longer than any specified path (i.e. pathless cookies come first),
            // because setting cookies with a path longer than the request path is of
            // limited use.
            int len1 = path1 == null ? Integer.MAX_VALUE : path1.length();
            int len2 = path2 == null ? Integer.MAX_VALUE : path2.length();

            // Rely on Arrays.sort's stability to retain creation order in cases where
            // cookies have same path length.
            return len2 - len1;
        }
    };

    /**
     * Encodes the specified cookies into a single Cookie header value.
     *
     * @param cookies
     *            some cookies
     * @return a Rfc6265 style Cookie header value, null if no cookies are passed.
     */
    public String encode(Cookie... cookies) {
        if (checkNotNull(cookies, "cookies").length == 0) {
            return null;
        }

        StringBuilder buf = stringBuilder();
        if (strict) {

Frequently Asked Questions

What is the ClientCookieEncoder class?
ClientCookieEncoder is a class in the netty codebase, defined in codec-http/src/main/java/io/netty/handler/codec/http/cookie/ClientCookieEncoder.java.
Where is ClientCookieEncoder defined?
ClientCookieEncoder is defined in codec-http/src/main/java/io/netty/handler/codec/http/cookie/ClientCookieEncoder.java at line 47.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free