@Nullable
    static Cookie decode(boolean strict, String header) {
        final int headerLen = header.length();
        assert headerLen != 0 : headerLen;

        CookieBuilder builder = null;

        loop: for (int i = 0;;) {

            // Skip spaces and separators.
            for (;;) {
                if (i == headerLen) {
                    break loop;
                }
                final char c = header.charAt(i);
                if (c == ',') {
                    // Having multiple cookies in a single Set-Cookie header is
                    // deprecated, modern browsers only parse the first one
                    break loop;
                }

                if (c == '\t' || c == '\n' || c == 0x0b || c == '\f' ||
                    c == '\r' || c == ' ' || c == ';') {
                    i++;
                    continue;
                }
                break;
            }

            final int nameBegin = i;
            final int nameEnd;
            final int valueBegin;
            int valueEnd;

            for (;;) {
                final char curChar = header.charAt(i);
                if (curChar == ';') {
                    // NAME; (no value till ';')
                    nameEnd = i;
                    valueBegin = valueEnd = -1;
                    break;
                }

                if (curChar == '=') {
                    // NAME=VALUE
                    nameEnd = i;
                    i++;
                    if (i == headerLen) {
                        // NAME= (empty value, i.e. nothing after '=')
                        valueBegin = valueEnd = 0;
                        break;
                    }

                    valueBegin = i;
                    // NAME=VALUE;
                    final int semiPos = header.indexOf(';', i);
                    valueEnd = i = semiPos > 0 ? semiPos : headerLen;
                    break;
                }

                i++;

                if (i == headerLen) {
                    // NAME (no value till the end of string)
                    nameEnd = headerLen;
                    valueBegin = valueEnd = -1;
                    break;
                }
            }

            if (valueEnd > 0 && header.charAt(valueEnd - 1) == ',') {
                // old multiple cookies separator, skipping it
                valueEnd--;
            }

            if (builder == null) {
                // cookie name-value pair
                builder = initCookie(logger, strict, header, nameBegin, nameEnd, valueBegin, valueEnd);
                if (builder == null) {
                    return null;
                }
            } else {
                // cookie attribute
                appendAttribute(builder, header, nameBegin, nameEnd, valueBegin, valueEnd);
            }
        }

        if (builder == null) {
            return null;
        }

        mergeMaxAgeAndExpires(builder, header);
        return builder.build();
    }
Decodes the specified {@code "Set-Cookie"} header value into a {@link Cookie}.

@param strict whether to validate the name and value chars are in the valid scope defined in RFC 6265.
@return the decoded {@link Cookie}, or {@code null} if malformed.
core/src/main/java/com/linecorp/armeria/common/ClientCookieDecoder.java