8000 [PsrHttpMessageBridge] Fix conversion of partitioned cookies in the PSR-7 bridge by stof · Pull Request #58010 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[PsrHttpMessageBridge] Fix conversion of partitioned cookies in the PSR-7 bridge #58010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,89 +132,12 @@ public function createResponse(ResponseInterface $psrResponse, bool $streamed =
$response->setProtocolVersion($psrResponse->getProtocolVersion());

foreach ($cookies as $cookie) {
$response->headers->setCookie($this->createCookie($cookie));
$response->headers->setCookie(Cookie::from 8000 String($cookie));
}

return $response;
}

/**
* Creates a Cookie instance from a cookie string.
*
* Some snippets have been taken from the Guzzle project: https://github.com/guzzle/guzzle/blob/5.3/src/Cookie/SetCookie.php#L34
*
* @throws \InvalidArgumentException
*/
private function createCookie(string $cookie): Cookie
{
foreach (explode(';', $cookie) as $part) {
$part = trim($part);

$data = explode('=', $part, 2);
$name = $data[0];
$value = isset($data[1]) ? trim($data[1], " \n\r\t\0\x0B\"") : null;

if (!isset($cookieName)) {
$cookieName = $name;
$cookieValue = $value;

continue;
}

if ('expires' === strtolower($name) && null !== $value) {
$cookieExpire = new \DateTime($value);

continue;
}

if ('path' === strtolower($name) && null !== $value) {
$cookiePath = $value;

continue;
}

if ('domain' === strtolower($name) && null !== $value) {
$cookieDomain = $value;

continue;
}

if ('secure' === strtolower($name)) {
$cookieSecure = true;

continue;
}

if ('httponly' === strtolower($name)) {
$cookieHttpOnly = true;

continue;
}

if ('samesite' === strtolower($name) && null !== $value) {
$samesite = $value;

continue;
}
}

if (!isset($cookieName)) {
throw new \InvalidArgumentException('The value of the Set-Cookie header is malformed.');
}

return new Cookie(
$cookieName,
$cookieValue,
$cookieExpire ?? 0,
$cookiePath ?? '/',
$cookieDomain ?? null,
isset($cookieSecure),
isset($cookieHttpOnly),
true,
$samesite ?? null
);
}

private function createStreamedResponseCallback(StreamInterface $body): callable
{
return function () use ($body) {
Expand Down
0