@Nullable
    public static Cookie parseSetCookie(String host, String setCookie) {
        int pos = 0;
        int limit = setCookie.length();
        int cookiePairEnd = delimiterOffset(setCookie, pos, limit, ';');

        int pairEqualsSign = delimiterOffset(setCookie, pos, cookiePairEnd, '=');
        if (pairEqualsSign == cookiePairEnd) {
            return null;
        }

        String cookieName = trimSubstring(setCookie, pos, pairEqualsSign);
        if (cookieName.isEmpty() || indexOfControlOrNonAscii(cookieName) != -1) {
            return null;
        }

        String cookieValue = trimSubstring(setCookie, pairEqualsSign + 1, cookiePairEnd);
        if (indexOfControlOrNonAscii(cookieValue) != -1) {
            return null;
        }

        long expiresAt = MAX_DATE;
        String domain = null;
        String path = null;
        long deltaSeconds = -1L;
        boolean secureOnly = false;
        boolean httpOnly = false;
        boolean hostOnly = true;
        boolean persistent = false;
        String priority = null;

        pos = cookiePairEnd + 1;
        while (pos < limit) {
            int attributePairEnd = delimiterOffset(setCookie, pos, limit, ';');

            int attributeEqualsSign = delimiterOffset(setCookie, pos, attributePairEnd, '=');
            String attributeName = trimSubstring(setCookie, pos, attributeEqualsSign);
            String attributeValue = attributeEqualsSign < attributePairEnd
                    ? trimSubstring(setCookie, attributeEqualsSign + 1, attributePairEnd)
                    : "";

            if (attributeName.equalsIgnoreCase("expires")) {
                try {
                    expiresAt = parseExpires(attributeValue, attributeValue.length());
                    persistent = true;
                } catch (IllegalArgumentException e) {
                    // Ignore this attribute, it isn't recognizable as a date.
                }
            } else if (attributeName.equalsIgnoreCase("max-age")) {
                try {
                    deltaSeconds = parseMaxAge(attributeValue);
                    persistent = true;
                } catch (NumberFormatException e) {
                    // Ignore this attribute, it isn't recognizable as a max age.
                }
            } else if (attributeName.equalsIgnoreCase("domain")) {
                domain = attributeValue;
            } else if (attributeName.equalsIgnoreCase("path")) {
                path = attributeValue;
            } else if (attributeName.equalsIgnoreCase("secure")) {
                secureOnly = true;
            } else if (attributeName.equalsIgnoreCase("httponly")) {
                httpOnly = true;
            } else if (attributeName.equalsIgnoreCase("priority")) {
                priority = attributeValue;
            }

            pos = attributePairEnd + 1;
        }

        if (TextUtils.isEmpty(domain)) {
            domain = host;
        }

        // If 'Max-Age' is present, it takes precedence over 'Expires', regardless of the order the two
        // attributes are declared in the cookie string.
        if (deltaSeconds == Long.MIN_VALUE) {
            expiresAt = Long.MIN_VALUE;
        } else if (deltaSeconds != -1L) {
            long deltaMilliseconds = deltaSeconds <= (Long.MAX_VALUE / 1000) ? deltaSeconds * 1000
                    : Long.MAX_VALUE;
            long currentTimeMillis = System.currentTimeMillis();
            expiresAt = currentTimeMillis + deltaMilliseconds;
            if (expiresAt > MAX_DATE) {
                // Handle overflow.
                expiresAt = MAX_DATE;
            }
        }
        return new Cookie(cookieName, cookieValue, expiresAt, domain, path, secureOnly, httpOnly,
                hostOnly, persistent, priority);
    }
Build a new cookie instance.

@return A Cookie.
netbare-injector/src/main/java/com/github/megatronking/netbare/http/Cookie.java