protected static function parseCookies(array $cookieHeader)
    {
        $cookies = [];
        foreach ($cookieHeader as $cookie) {
            if (strpos($cookie, '";"') !== false) {
                $cookie = str_replace('";"', '{__cookie_replace__}', $cookie);
                $parts = preg_split('/\;[ \t]*/', $cookie);
                $parts = str_replace('{__cookie_replace__}', '";"', $parts);
            } else {
                $parts = preg_split('/\;[ \t]*/', $cookie);
            }

            list($name, $value) = explode('=', array_shift($parts), 2);
            $parsed = ['name' => $name, 'value' => urldecode($value)];

            foreach ($parts as $part) {
                if (strpos($part, '=') !== false) {
                    list($key, $value) = explode('=', $part);
                } else {
                    $key = $part;
                    $value = true;
                }

                $key = strtolower($key);
                if ($key === 'httponly') {
                    $key = 'httpOnly';
                }
                if ($key === 'expires') {
                    $key = 'expire';
                    $value = strtotime($value);
                }
                if (!isset($parsed[$key])) {
                    $parsed[$key] = $value;
                }
            }
            $cookies[] = $parsed;
        }

        return $cookies;
    }