private function getSetCookieHeaderValue(Cookie $cookie): string
    {
        $headerValue = "{$cookie->getName()}=" . urlencode($cookie->getValue());

        if (($expiration = $cookie->getExpiration()) !== null) {
            $headerValue .= '; Expires=' . $expiration->format(self::EXPIRATION_DATE_FORMAT);
        }

        if (($maxAge = $cookie->getMaxAge()) !== null) {
            $headerValue .= "; Max-Age=$maxAge";
        }

        if (($domain = $cookie->getDomain()) !== null) {
            $headerValue .= '; Domain=' . urlencode($domain);
        }

        if (($path = $cookie->getPath()) !== null) {
            $headerValue .= '; Path=' . urlencode($path);
        }

        if ($cookie->isSecure()) {
            $headerValue .= '; Secure';
        }

        if ($cookie->isHttpOnly()) {
            $headerValue .= '; HttpOnly';
        }

        if (($sameSite = $cookie->getSameSite()) !== null) {
            $headerValue .= '; SameSite=' . urlencode($sameSite);
        }

        return $headerValue;
    }