private void extractKeyValuePairs(
            String header, List<String> names, List<String> values) {
        Matcher m = PATTERN.matcher(header);
        int pos = 0;
        String name = null;
        String value = null;
        String separator = null;
        while (m.find(pos)) {
            pos = m.end();

            // Extract name and value pair from the match.
            String newName = m.group(1);
            String newValue = m.group(3);
            if (newValue == null) {
                newValue = decodeValue(m.group(2));
            }
            String newSeparator = m.group(4);

            if (name == null) {
                name = newName;
                value = newValue == null? "" : newValue;
                separator = newSeparator;
                continue;
            }

            if (newValue == null &&
                !CookieHeaderNames.DISCARD.equalsIgnoreCase(newName) &&
                !CookieHeaderNames.SECURE.equalsIgnoreCase(newName) &&
                !CookieHeaderNames.HTTPONLY.equalsIgnoreCase(newName)) {
                value = value + separator + newName;
                separator = newSeparator;
                continue;
            }

            names.add(name);
            values.add(value);

            name = newName;
            value = newValue;
            separator = newSeparator;
        }

        // The last entry
        if (name != null) {
            names.add(name);
            values.add(value);
        }
    }